Unable to pull results from MS Graph using powershell
Simon De Barr
1
Reputation point
Hi Guys
We've pushed a PS script out via Intune to collect some data from end user devices. This has all worked perfectly, and if I log into MS Graph I can see the results of this at the URL:
https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/c<scriptid>/deviceRunStates
However, if I try and pull down the same results using PowerShell:
$result = Invoke-MSGraphRequest -HttpMethod GET -Url 'deviceManagement/deviceManagementScripts/<scriptid>/deviceRunStates?$expand=managedDevice' | Get-MSGraphAllPages
I get the following error, which seems to indicate it can't find the referenced script object (I've set the environment to beta in PS):
Invoke-MSGraphRequest : 400 Bad Request
{"error":{"code":"BadRequest","message":"Resource not found for the segment
'deviceManagementScripts'.","innerError":{"date":"2022-11-18T17:48:41","request-id":"b5bef45b-7c7f-45ca-9f8a-9ea0077fe21e","client-request-id":"b5bef45b-7c7f-45ca-9f8a-9ea0077fe21e"}}}
At line:1 char:11
+ $result = Invoke-MSGraphRequest -HttpMethod GET -Url 'deviceManagemen ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ConnectionError: (@{Request=; Response=}:PSObject) [Invoke-MSGraphRequest], HttpRequestException
+ FullyQualifiedErrorId : PowerShellGraphSDK_HttpRequestError,Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.InvokeRequest
Anyone got any idea where I'm going wrong?
TIA
Si
Windows for business Windows Server User experience PowerShell
8,330 questions
Microsoft Security Intune Other
5,569 questions
Sign in to answer