This works for me in the beta and 1.0 versions.
How to fetch Object ID from Device Name
I would like to have an API where I put in the Device Name and fetch the Object ID and AAD ID of the device.
As per article: https://learn.microsoft.com/en-us/graph/api/device-get?view=graph-rest-1.0&tabs=http, the query is being run using object ID.
I tried to use API: https://graph.microsoft.com/v1.0/devices/?$filter(displayName eq 'DESKTOP-RRNFP6H')&$select=id,deviceId,displayName however it returned me all the device including the specified device.
Request some help on this please.
Thanks.
Microsoft Security Microsoft Entra Microsoft Entra ID
Microsoft Security Intune Other
Microsoft Security Microsoft Graph
1 additional answer
Sort by: Most helpful
-
Deepanshukatara-6769 16,565 Reputation points Moderator
2023-08-25T05:35:50.01+00:00 Hope you are having a great day!
The
$filter
parameter might not be supported for thedisplayName
field in the Microsoft Graph API, which could be why you're getting all devices instead of just the specified one. In this case, you might need to retrieve all devices and then filter the results on your end based on thedisplayName
you're looking for. You can use device ID parameter.So , The following request retrieves the id and extensionAttributes property of a device.
Moreover, if you need to do using deviceName/displayName , you can use below script to achieve this .
$deviceName = "DESKTOP-RRNFP6H" $uri = "https://graph.microsoft.com/v1.0/devices?$select=id,deviceID,displayName" $accessToken = "YOUR_ACCESS_TOKEN_HERE" # Replace with your actual access token $headers = @{ "Authorization" = "Bearer $accessToken" } $response = Invoke-Rest Method -Uri $uri -Headers $headers -Method Get if ($response.StatusCode -eq 200) { $devices = $response.value for each ($device in $devices) { if ($device.displayName -eq $deviceName) { $deviceId = $device.id $aadId = $device.deviceID Write-Host "Device Name: $deviceName" Write-Host "Object ID: $deviceId" Write-Host "AAD ID: $aadId" break } } } else { Write-Host "Error: $($response.StatusCode) - $($response.Content)" }