Share via

Beta Graph API - deviceRunStates- filter not works

Kyuzo88 106 Reputation points
2025-10-31T13:57:32.3633333+00:00

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
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.