An API that connects multiple Microsoft services, enabling data access and automation across platforms
Beta Graph API - deviceRunStates- filter not works
Kyuzo88
106
Reputation points
I need to filter server-side the results of a script execution on the devices. I would like to retrieve the result for a specific device. To do this, I used this call:
GET /deviceManagement/deviceManagementScripts/{deviceManagementScriptId}/deviceRunStates/{deviceManagementScriptDeviceStateId}
Documentation: Get deviceManagementScriptDeviceState - Microsoft Graph beta
I queried the resultMessage column and it works, but I can't filter for a single device. Here is my PowerShell code:
$TargetRunStateId = "${ScriptId}:${DeviceId}"
$GraphCPU = "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/${ScriptId}/deviceRunStates/${TargetRunStateId}"
$ResponseCPU = Invoke-RestMethod -Uri $GraphCPU -Headers $Headers -Method GET
$ResponseCPU.value | Format-List
Error returned:
{ "error": { "code": "No method match route template", "message": "No OData route exists that match template ~/singleton/navigation/key/navigation/key with http verb GET for request /DeviceFE/StatelessDeviceFEService/deviceManagement/deviceManagementScripts('${ScriptId}')/deviceRunStates('${ScriptId}:${DeviceId}').", "innerError": { "date": "2025-10-30T14:34:41", "request-id": "xx", "client-request-id": "xxxxxxx" } } }
If I use this alternative code:
$TargetRunStateId = "${ScriptId}:${DeviceId}"
$GraphCPU = "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/${ScriptId}/userRunStates/${ScriptId}:${userId}/deviceRunStates?`$filter=id eq '${TargetRunStateId}'"
$ResponseCPU = Invoke-RestMethod -Uri $GraphCPU -Headers $Headers -Method GET
$ResponseCPU.value | Format-List
It works in that it returns results, but the filter does not work, and it returns all deviceRunStates.
Could you help me on this ?
Microsoft Security | Microsoft Graph
Microsoft Security | Microsoft Graph
Sign in to answer