Skip to content

Instantly share code, notes, and snippets.

@xtrasimplicity
Created May 24, 2024 05:15
Show Gist options
  • Save xtrasimplicity/aa951b162cc21c13f18418dbc3aa72aa to your computer and use it in GitHub Desktop.
Save xtrasimplicity/aa951b162cc21c13f18418dbc3aa72aa to your computer and use it in GitHub Desktop.
Action1 - Directory Services Registration state - Parse the output of dsregcmd /status
$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