-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGet-DSRegistrationStatus.ps1
46 lines (42 loc) · 1.4 KB
/
Get-DSRegistrationStatus.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Function Get-DSRegistrationStatus {
[cmdletbinding()]
Param(
[validateset('Json','PSCustomObject','List')]
$OutputType = 'PSCustomObject'
)
begin {
$text = dsregcmd /status | Out-String
$ht = [ordered]@{}
}
process {
$text -split '(?s)\r?\n[\s]+\+-+\+\r?\n\|' | ForEach-Object {
if($_ -match '(?s)\s?([\w\s]+?)(?=\s{2,})(.+)'){
$prop = $matches.1
$ht.$prop = [ordered]@{}
switch -Regex ($matches.2 -split '\r?\n'){
':' {$ht.$prop += $_ -replace ':','=' -replace '\\','\\' | ConvertFrom-StringData}
}
$ht.$prop = [PSCustomObject]$ht.$prop
}
}
$obj = [pscustomobject]$ht
switch($OutputType){
json {$obj | ConvertTo-Json -Depth 4}
pscustomobject {$obj}
list {
Write-Host `n -NoNewline
$props = $obj.psobject.properties.name
$propline = @{
Object = "------------------ $prop ------------------"
}
if($PSVersionTable.PSVersion.Major -le 5){
$propline.Add('NoNewLine',$true)
}
foreach($prop in $props){
Write-Host @propline
$obj.$prop | Format-List
}
}
}
}
}