我的 Windows 10 个人设备连接了几个“工作或学校”帐户。有没有办法使用 cmd 或 PowerShell 获取这些帐户的列表?
在最近的 Windows 11 内部版本中dsregcmd /listaccounts
,但我正在寻找一种在 Windows 10 和 Windows 11 21H2 上开箱即用的解决方案。
在 Windows 10(21H2)和 Windows 11(21H2)上,我看不到/listaccounts
开启dsregcmd
帮助。
Windows 10(21H2):
cmd> ver
Microsoft Windows [Version 10.0.19044.1645]
cmd> dsregcmd /?
DSREGCMD switches
/? : Displays the help message for DSREGCMD
/status : Displays the device join status
/status_old : Displays the device join status in old format
/join : Schedules and monitors the Autojoin task to Hybrid Join the device
/leave : Performs Hybrid Unjoin
/debug : Displays debug messages
/refreshprt : Refreshes PRT in the CloudAP cache
cmd>
Windows 11(21H2):
cmd> ver
Microsoft Windows [Version 10.0.22000.613]
cmd> dsregcmd /?
DSREGCMD switches
/? : Displays the help message for DSREGCMD
/status : Displays the device join status
/status_old : Displays the device join status in old format
/join : Schedules and monitors the Autojoin task to Hybrid Join the device
/leave : Performs Hybrid Unjoin
/debug : Displays debug messages
/refreshprt : Refreshes PRT in the CloudAP cache
cmd>
Windows 11 Insider 版本(有/listaccounts
开关):
cmd>ver
Microsoft Windows [Version 10.0.22598.200]
cmd>dsregcmd /?
DSREGCMD switches
/? : Displays the help message for DSREGCMD
/status : Displays the device join status
/status_old : Displays the device join status in old format
/join : Schedules and monitors the Autojoin task to Hybrid Join the device
/leave : Performs Hybrid Unjoin
/debug : Displays debug messages
/refreshprt : Refreshes PRT in the CloudAP cache
/refreshp2pcerts : Refreshes P2P certificates
/cleanupaccounts : Deletes all WAM accounts
/listaccounts : Lists all WAM accounts
/UpdateDevice : Update device attributes to Azure AD
cmd>
答案1
这是我针对 Windows 10 的想法。只需将此函数复制/粘贴到 powershell 控制台并执行即可。它将读出 WorkplaceThumbprint 并在注册表中搜索它。如果存在帐户,则可以在 Registry-Hive 中找到 UserEmail。
function CheckForBusinessOrSchoolAccount {
$x=(dsregcmd /status | select-string -Pattern "WorkplaceThumbprint" | out-string).Trim()
switch (!$x) {
$true {
Write-Host "No Business/School-Account found on this Host"
}
$false {
$y=$x.LastIndexOf(":")
$AccountThumbPrint=$x.Substring($y+2)
$AccountMailAddress=(Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WorkplaceJoin\JoinInfo\$AccountThumbPrint" -Name UserEmail | select UserEmail | ft -HideTableHeaders | out-string).Trim()
Write-Host "We found an existing Account with Thumbprint $AccountThumbPrint and Mail-Address $AccountMailAddress."
}
}
}