Last active
August 12, 2021 07:50
-
-
Save alexinnes/5a0263f57bef8f00431dca923faa63d3 to your computer and use it in GitHub Desktop.
Get-VSSWriters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-VSSWriters { | |
<# | |
.Synopsis | |
Performs VSSAdmin list writers | |
.DESCRIPTION | |
Gets the VSS Writers and outputs it as a object. | |
.EXAMPLE | |
Get-VSSWriters | |
.NOTES | |
Uses regex to get the information and then splits it into objects. | |
#> | |
Begin { | |
[string]$vssWriters = (vssadmin list writers) | Out-String | |
#Regex to findthe first line and then its proceeding 4 lines | |
$reg = [regex]::matches($vssWriters, '(Writer name:.*\n.*\n.*\n.*\n.*)') | |
$vssObject = @() | |
$VSSOutput = @() | |
$VSS = @() | |
} | |
Process { | |
#loop thought the regex matches and split them into their properties. | |
foreach($value in $reg.value){ | |
$vssObject = New-Object PSCustomObject -Property([ordered]@{ | |
WriterName = ([regex]::Match($value,"Writer name: \'(.*)\'")).groups[1].value | |
WriterId = ([regex]::Match($value,"Writer Id: (.*)")).groups[1].value | |
WriterInstanceId = ([regex]::Match($value,"Writer Instance Id: (.*)")).groups[1].value | |
State = ([regex]::Match($value,"State: \[(.)\]")).groups[1].value | |
StateInfo = ([regex]::Match($value,"State: \[(.)\] (.*)")).groups[2].value | |
LastError = ([regex]::Match($value,"Last error: (.*)")).groups[1].value | |
}) | |
$VSSOutput += $vssObject | |
} | |
} | |
End { | |
$VSSOutput | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment