Created
May 24, 2024 05:15
-
-
Save xtrasimplicity/aa951b162cc21c13f18418dbc3aa72aa to your computer and use it in GitHub Desktop.
Action1 - Directory Services Registration state - Parse the output of dsregcmd /status
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
$raw = dsregcmd /status | |
$result = New-Object -TypeName psobject | |
function Sanitise-For-Property-Name($str) { | |
return $str.Trim().Replace(" ", "_"); | |
} | |
$sectionName = "" | |
foreach($line in $($raw -split "`r`n")) { | |
if ($line -match "^\|(.+)\|$") { | |
$sectionName = Sanitise-For-Property-Name $Matches[1] | |
} | |
if ($line -match "(.*) : (.*)") { | |
$propertyName = Sanitise-For-Property-Name $Matches[1] | |
$propertyValue = $Matches[2] | |
$result | Add-Member -MemberType NoteProperty -Name "$($sectionName)_$($propertyName)" -Value $propertyValue -Force | |
} | |
} | |
$result | Add-Member -MemberType NoteProperty -Name "A1_Key" -Value $(hostname) | |
$result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment