Forum Discussion
AEchtermeijer
Jun 09, 2022Copper Contributor
Question: Script to see if device is Azure AD joined
We often receive notebooks that are still joined to a Azure AD tenant. Is there a (simple) Powershell script that shows if a device is still joined to a tenant? Knowing which exact tenant the device ...
Jun 10, 2022
$subKey = Get-Item "HKLM:/SYSTEM/CurrentControlSet/Control/CloudDomainJoin/JoinInfo"
$guids = $subKey.GetSubKeyNames()
foreach($guid in $guids) {
$guidSubKey = $subKey.OpenSubKey($guid);
$tenantId = $guidSubKey.GetValue("TenantId");
$userEmail = $guidSubKey.GetValue("UserEmail");
}
write-host $tenantId $userEmail
(Got this from https://nerdymishka.com/articles/azure-ad-domain-join-registry-keys/ , it works for me and shows me the tenantid and the account which was used for joining)
$guids = $subKey.GetSubKeyNames()
foreach($guid in $guids) {
$guidSubKey = $subKey.OpenSubKey($guid);
$tenantId = $guidSubKey.GetValue("TenantId");
$userEmail = $guidSubKey.GetValue("UserEmail");
}
write-host $tenantId $userEmail
(Got this from https://nerdymishka.com/articles/azure-ad-domain-join-registry-keys/ , it works for me and shows me the tenantid and the account which was used for joining)
- B4ArtMay 13, 2024Brass Contributor
A little extension to your script:
$subKey = Get-Item "HKLM:/SYSTEM/CurrentControlSet/Control/CloudDomainJoin/TenantInfo/$tenantId"
$tenantInfo = $subKey.GetValue("DisplayName")
write-host $tenantInfoAnd for completeness:
$subKey = Get-Item "HKLM:/SYSTEM/CurrentControlSet/Control/CloudDomainJoin/JoinInfo" $guids = $subKey.GetSubKeyNames() foreach($guid in $guids) { $guidSubKey = $subKey.OpenSubKey($guid) $tenantId = $guidSubKey.GetValue("TenantId") $userEmail = $guidSubKey.GetValue("UserEmail") } $subKey = Get-Item "HKLM:/SYSTEM/CurrentControlSet/Control/CloudDomainJoin/TenantInfo/$tenantId" $tenantInfo = $subKey.GetValue("DisplayName") write-host $tenantId write-host $tenantInfo write-host $userEmail