Skip to content

Instantly share code, notes, and snippets.

@aaronparker
Created September 23, 2025 23:41
Show Gist options
  • Select an option

  • Save aaronparker/847ac65d2286e59f0eb71292ee08c5ab to your computer and use it in GitHub Desktop.

Select an option

Save aaronparker/847ac65d2286e59f0eb71292ee08c5ab to your computer and use it in GitHub Desktop.
A PowerShell wrapper for dsregcmd /status. Returns output as a PowerShell object
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
@aaronparker
Copy link
Author

Example output:

AzureAdJoined             : True
EnterpriseJoined          : False
DomainJoined              : False
VirtualDesktop            : NOT SET
DeviceName                : AU-F05B61AE5328
DeviceId                  : cf192fd8-7bd2-50bf-8297-24d268e7fa4a
Thumbprint                : B79F17870D8021454604705DF49105D349BD0A40
DeviceCertificateValidity : @{ValidFrom=2025-04-23T15:42:31.0000000Z; ValidTo=2035-04-23T16:12:31.0000000Z}
KeyContainerId            : 17508b34-4bac-4fe7-8e1f-c91b9415d817
KeyProvider               : Microsoft Platform Crypto Provider
TpmProtected              : True
DeviceAuthStatus          : SUCCESS
TenantName                : stealthpuppy
TenantId                  : 4a75621c-h347-40ab-ab83-707f34562280
AuthCodeUrl               : https://login.microsoftonline.com/4a75621c-h347-40ab-ab83-707f34562280/oauth2/authorize
AccessTokenUrl            : https://login.microsoftonline.com/4a75621c-h347-40ab-ab83-707f34562280/oauth2/token
MdmUrl                    : https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc
MdmTouUrl                 : https://portal.manage.microsoft.com/TermsofUse.aspx
MdmComplianceUrl          : https://portal.manage.microsoft.com/?portalAction=Compliance
SettingsUrl               : rtJVcmlzIjpbImh0dHBzOi8cv2FpbGFuaTEwLm9uZS5hjWNyb3NvZnQuY12tLyIsImh0dHBzOi8va2FpbGFuaTExLm9uZS5taWNyb3NvZnQuY29tLyJdfQ==
JoinSrvVersion            : 2.0
JoinSrvUrl                : https://enterpriseregistration.windows.net/EnrollmentServer/device/
JoinSrvId                 : urn:ms-drs:enterpriseregistration.windows.net
KeySrvVersion             : 1.0
KeySrvUrl                 : https://enterpriseregistration.windows.net/EnrollmentServer/key/
KeySrvId                  : urn:ms-drs:enterpriseregistration.windows.net
WebAuthNSrvVersion        : 1.0
WebAuthNSrvUrl            : https://enterpriseregistration.windows.net/webauthn/4a75621c-h347-40ab-ab83-707f34562280/
WebAuthNSrvId             : urn:ms-drs:enterpriseregistration.windows.net
DeviceManagementSrvVer    : 1.0
DeviceManagementSrvUrl    : https://enterpriseregistration.windows.net/manage/4a75621c-h347-40ab-ab83-707f34562280/
DeviceManagementSrvId     : urn:ms-drs:enterpriseregistration.windows.net
NgcSet                    : True
NgcKeyId                  : {B8F50C38-D36E-4748-8788-579F8B3C90FF}
CanReset                  : DestructiveAndNonDestructive
WorkplaceJoined           : False
WamDefaultSet             : True
WamDefaultAuthority       : organizations
WamDefaultId              : https://login.microsoft.com
WamDefaultGUID            : {C16898F6-B248-4967-8171-74D745DA4520}
AzureAdPrt                : True
AzureAdPrtUpdateTime      : 2025-09-23T12:27:33.0000000Z
AzureAdPrtExpiryTime      : 2025-10-07T11:27:36.0000000Z
AzureAdPrtAuthority       : https://login.microsoftonline.com/4a75621c-h347-40ab-ab83-707f34562280
EnterprisePrt             : False
EnterprisePrtAuthority    :
OnPremTgt                 : False
CloudTgt                  : True
KerbTopLevelNames         : {.windows.net, .windows.net:1433, .windows.net:3342, .azure.net…}
AadRecoveryEnabled        : False
ExecutingAccountName      : {AzureAD\Aaron, aaron@test.stealthpuppy.com}
KeySignTest               : PASSED
DisplayNameUpdated        : Managed by MDM
OsVersionUpdated          : Managed by MDM
HostNameUpdated           : True
LastHostNameUpdate        : SUCCESS
ClientTime                : 2025-04-23T19:23:53.0000000Z
RequestID                 : 3d0397d9-42af-40ac-b791-44efbf57ab6e
ServerTime                : 2025-04-24T05:23:53.0000000Z
HTTPStatus                : 200
ServerMessage             : The attribute 'hostnames' value(s) were successfully updated
AutoDetectSettings        : True
AutoConfigurationURL      :
ProxyServerList           :
ProxyBypassList           :
AccessType                : DIRECT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment