Blog Post
Identify Device state in EntraID/Defender with PowerShell
Great blog! Love that we get to see the technical part and the actual scripts etc :).
But maybe im missing something here, the api.securitycenter.microsoft.com is never called and the script is not doing anything with Defender XDR API. So basically the script above is just using an appregistration to check status of devices in Entra ID. (from a text file).
So, if you have the rights to read devices in your tenant and Microsoft Graph has the right scopes delegated (approved). You can use this oneliner:
Connect-MgGraph -Scopes "Device.Read.All"; Get-Content "C:\temp\devices.txt" | % { $n=$_; $d=Get-MgDevice -Filter "displayName eq '$($n -replace '''','''''')'" -Property "id,deviceId,displayName,accountEnabled"; if($d){ $d | Select @{n='InputName';e={$n}}, @{n='DisplayName';e={$_.DisplayName}}, @{n='Status';e={if($_.AccountEnabled){'Enabled'} else {'Disabled'}}}, @{n='DeviceId';e={$_.DeviceId}}, @{n='ObjectId';e={$_.Id}} } else { [pscustomobject]@{ InputName=$n; DisplayName=$null; Status='Not Found'; DeviceId=$null; ObjectId=$null } } } | Format-Table -AutoSize
I added deviceID and objectID in the ouput as devices in Entra can have the same name, but different ID.
And if you want to use the scope of your admin account, just remove: (ie: use your Entra ID Role that might already have the scope).
-Scopes "Device.Read.All"
- edgarus71Oct 23, 2025
Microsoft
Hi John, thank you for your kind words. Actually, I don't use the api.securitycenter.microsoft.com directly, I just add an API permission in the app registration access to the WindowsDefendeATP, so I can read details from the machines.