Created
September 23, 2025 23:41
-
-
Save aaronparker/847ac65d2286e59f0eb71292ee08c5ab to your computer and use it in GitHub Desktop.
A PowerShell wrapper for dsregcmd /status. Returns output as a PowerShell object
This file contains hidden or 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 ConvertTo-UniversalTime { | |
| param ([System.String]$String) | |
| try { | |
| $dt = [DateTime]::ParseExact($String, "yyyy-MM-dd HH:mm:ss.fff UTC", $null) | |
| return $dt.ToUniversalTime().ToString("o") | |
| } | |
| catch { | |
| $dt = [DateTime]::ParseExact($String, "MM-dd-yyyy H:mm:ss'Z'", $null, [System.Globalization.DateTimeStyles]::AssumeUniversal) | |
| return $dt.ToUniversalTime().ToString("o") | |
| } | |
| } | |
| function Get-DsRegStatus { | |
| $Output = & "$Env:SystemRoot\System32\dsregcmd.exe" /status | Out-String | |
| $DsRegTable = $Output -split "`n" | ForEach-Object { | |
| if ($_ -match "^(.*?):\s*(.*)$") { | |
| [PSCustomObject]@{ | |
| Key = $matches[1].Trim() | |
| Value = $matches[2].Trim() | |
| } | |
| } | |
| } | |
| $DsRegObject = [PSCustomObject]@{} | |
| foreach ($item in $DsRegTable) { | |
| switch ($item.Value) { | |
| "YES" { $item.Value = $true } | |
| "NO" { $item.Value = $false } | |
| } | |
| if ($item.Key -notlike "For more information*") { | |
| switch -regex ($item.Key) { | |
| "AzureAdPrtUpdateTime|AzureAdPrtExpiryTime|Client Time|Server Time" { | |
| $DsRegObject | Add-Member -MemberType "NoteProperty" -Name ($item.Key -replace "\s+", "") -Value (ConvertTo-UniversalTime $item.Value) | |
| } | |
| "Executing Account Name|KerbTopLevelNames" { | |
| $DsRegObject | Add-Member -MemberType "NoteProperty" -Name ($item.Key -replace "\s+", "") -Value (($item.Value -split ",").Trim()) | |
| } | |
| "WamDefaultGUID" { | |
| $DsRegObject | Add-Member -MemberType "NoteProperty" -Name ($item.Key -replace "\s+", "") -Value ($item.Value -replace "\s+\(AzureAd\)", "") | |
| } | |
| "DeviceCertificateValidity" { | |
| $Times = $($item.Value -split "--").Trim("[ ]") | |
| $CertificateValidity = [PSCustomObject]@{ | |
| ValidFrom = ConvertTo-UniversalTime $Times[0] | |
| ValidTo = ConvertTo-UniversalTime $Times[1] | |
| } | |
| $DsRegObject | Add-Member -MemberType "NoteProperty" -Name $item.Key -Value $CertificateValidity | |
| } | |
| default { | |
| $DsRegObject | Add-Member -MemberType "NoteProperty" -Name ($item.Key -replace "\s+|-", "") -Value $item.Value | |
| } | |
| } | |
| } | |
| } | |
| return $DsRegObject | |
| } | |
| Get-DsRegStatus |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: