有没有办法以编程方式确定 Windows 计算机是否作为 SYSTEM 加入 AAD?

pha*_*rus 6 windows powershell entra-id

我希望能够通过脚本确定给定的 Windows 工作站是加入 AAD、混合 AD 还是加入本地 AD。

我想从我正在使用的 RMM 运行此脚本,这样我就可以将这些结果存储在 RMM 中,并能够轻松地将计算机分为这三个类别(加上一个用于未加入任何类型域的工作站的类别)。

我使用的 RMM 以 NT AUTHORITY\SYSTEM 身份运行 powershell 脚本。

获取此信息的通常推荐方法是运行命令

dsregcmd /status
Run Code Online (Sandbox Code Playgroud)

然而,根据微软的文档

dsregcmd /status 实用程序必须作为域用户帐户运行。

我在自己的测试中验证了在 Powershell 中运行 dsregcmd /status 作为 NT AUTHORITY\SYSTEM 返回错误

dsregcmd : The term 'dsregcmd' is not recognized as the name of a cmdlet, function, script file, or operable program.
Run Code Online (Sandbox Code Playgroud)

在 cmd 中运行该命令会返回类似的错误。

当我尝试指定 dsregcmd.exe 的完整路径时,错误是相同的。

有没有办法让这个命令在以 SYSTEM 身份运行时起作用?或者,是否有另一种方法可以确定工作站在以 SYSTEM 身份运行时是否已加入 AAD?

mfi*_*nni 7

查询注册表\n https://nerdymishka.com/articles/azure-ad-domain-join-registry-keys/

\n
\n

确定计算机是否已加入 AzureAd\nHKLM:/SYSTEM/CurrentControlSet/Control/CloudDomainJoin/JoinInfo/{Guid}

\n

在该键下,可以找到以下键: \xe2\x80\x93 TenantId \xe2\x80\x93\nUserEmail

\n
\n
$subKey = Get-Item "HKLM:/SYSTEM/CurrentControlSet/Control/CloudDomainJoin/JoinInfo"\n\n$guids = $subKey.GetSubKeyNames()\nforeach($guid in $guids) {\n    $guidSubKey = $subKey.OpenSubKey($guid);\n    $tenantId = $guidSubKey.GetValue("TenantId");\n    $userEmail = $guidSubKey.GetValue("UserEmail");\n}\n
Run Code Online (Sandbox Code Playgroud)\n