Created
November 26, 2019 01:30
-
-
Save sandytsang/b9a90a31bfc728c28d527b3ac011eb07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $scope = "https://graph.microsoft.com/.default" | |
| $Tenants = @("tenant1.onmicrosoft.com", "tenant2.onmicrosoft.com", "tenant3.onmicrosoft.com") #List here your tenants | |
| $AppID = "10f9be91-4c9b-4427-aa71-143d18abafb5" #Change this to your own app ID | |
| $AppSecret = "vJctTjssIeidhuzNQDkfWUIF/Pe+ae+adfafafafaf" #Change this to your own App Secret | |
| #Get device serial number | |
| #$Serial = (Get-WmiObject -Class Win32_BIOS).SerialNumber | |
| #Device Serial number, change this! | |
| $Serial = "PC03SVKGXXX" | |
| $authHeader = @{ | |
| 'Content-Type' = 'application/x-www-form-urlencoded' | |
| } | |
| $authBody = @{ | |
| 'client_id'=$AppId | |
| 'grant_type'="client_credentials" | |
| 'client_secret'="$AppSecret" | |
| 'scope'= $scope | |
| } | |
| foreach ($Tenant in $Tenants) { | |
| #Change token authority endpont | |
| $authority = "https://login.microsoftonline.com/$tenant/oauth2/v2.0/token" | |
| #Get Access Token | |
| $Request = Invoke-RestMethod -Headers $authHeader -Uri $authority -Body $authBody -Method POST | |
| $AuthToken = @{ | |
| Authorization = "Bearer $($Request.access_token)" | |
| } | |
| Write-Host "checking from tenant : $Tenant" -ForegroundColor Yellow | |
| #URL for query autopilot device, always use filter, this moment only support contains as filter | |
| $url = "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities?`$filter=contains(serialNumber,'$Serial')" | |
| $AutopilotDevice = Invoke-RestMethod -Method Get -Uri $url -Headers $AuthToken -ErrorAction Continue | |
| if ($AutopilotDevice.'@odata.count' -eq "1") | |
| { | |
| write-host "found device serial $Serial in tenant $Tenant" -ForegroundColor Green | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment