Powershell 2.0
I am looking to extract the Exchanges-specific entries from the output of running the "vssadmin list writers" command, which gives you the results for all the VSS writers on the system and doesn't let you filter by writer name. What is the best way
to extract these specific lines from the output? I really just want the writer name, the state, and the last error. The end goal will be to compile these entries for each mailbox server so that we can quickly check the VSS state in case of any issues with
backups.
Writer name: 'Microsoft Exchange Writer'
Writer Id: {**GUID**}
Writer Instance Id: {**GUID**}
State: [1] Stable
Last error: No error
Writer name: 'Microsoft Exchange Replica Writer'
Writer Id: {**GUID**}
Writer Instance Id: {**GUID**}
State: [1] Stable
Last error: No error
Extracting specific entries from vssadmin output
December 20th, 2013 11:48am
(vssadmin list writers | where {$_.Trim()}) -split "`r`n" | foreach {
if ($_.StartsWith("Writer name")){
$ht=@{}
}
$key,$val=$_ -split ": "
$ht.Add($key,$val)
if ($_.StartsWith("Last Error")){
New-Object PSObject -Property $ht
}
} | select "Writer Name",State,"Last Error"
Free Windows Admin Tool Kit Click here and download it now
December 20th, 2013 12:19pm
$AllData = vssadmin list writers
$WriterNames = $AllData | findstr /i "name:"
$States = $AllData | findstr /i "State:"
$LastErrors = $AllData | findstr /i "error:"
$i = 0
ForEach ($Writer in $WriterNames) {
If ($Writer -like '*Exchange*') {
Write-Output $Writer $States[$i] $LastErrors[$i] "`r"
$i++
}
}
December 20th, 2013 1:19pm


