PowerShell Regex with VSS command -
i wanted select select "writer name","writer id" , "writer instance id" output of "vssadmin list writers", needed on how go using regex , create powershell objects, can 1 help
ps c:\windows\system32> $list = vssadmin list writers ps c:\windows\system32> $list vssadmin 1.1 - volume shadow copy service administrative command-line tool (c) copyright 2001-2012 microsoft corp. writer name: 'task scheduler writer' writer id: {d61d61c8-d73a-4eee-8cdd-f6f9786b7124} writer instance id: {1bddd48e-5052-49db-9b07-b96f96727e6b} state: [1] stable last error: no error writer name: 'vss metadata store writer' writer id: {75dfb225-e2e4-4d39-9ac9-ffaff65ddf06} writer instance id: {088e7a7d-09a8-4cc6-a609-ad90e75ddc93} state: [1] stable last error: no error writer name: 'performance counters writer' writer id: {0bada1de-01a9-4625-8278-69e735f39dd2} writer instance id: {f0086dda-9efc-47c5-8eb6-a944c3d09381} state: [1] stable last error: no error writer name: 'system writer' writer id: {e8132975-6f93-4464-a53e-1050253ae220} writer instance id: {cb8da305-5a18-4bf9-91e6-981bcf836c7b} state: [9] failed last error: timed out
if want objects, trick:
$cvssoutput = vssadmin list writers # creating empty collection. $cvsswriters = @() foreach ($line in $cvssoutput) { $cnamevalue = $line.trim() -split ': ' if ($cnamevalue[1] -ne $null) { if ($cnamevalue[0] -eq 'writer name') { # new writer. initializing new object. $ovssvriter = new-object psobject } # formatting , adding properties. $sname = $cnamevalue[0] -replace " ", "" $svalue = $cnamevalue[1] -replace "'", "" $ovssvriter | add-member -type noteproperty -name $sname -value $svalue if ($cnamevalue[0] -eq 'last error') { # properties in place. # adding object collection. $cvsswriters += $ovssvriter } } }
now can select properties need, example:
$cvsswriters | % { $_.writername }
Comments
Post a Comment