MSGraph usage query

Newbie Jones 1,386 Reputation points
2022-12-15T11:28:48.63+00:00

I'm just getting my head around MS Graph usage, and I have a couple of queries.

I'm starting off with a fairly basic query, and using Graph Explorer to review the options before crossing over the the PowerShell cmdlets.

I'm using Get-MgDevice and returning any Surface Go 2.

https://graph.microsoft.com/v1.0/devices?$search="model:Surface Go 2"&$select=id, model, displayName  

Converting this to PowerShell.

    Get-MgDevice -search="model:Surface Go 2" -ConsistencyLevel eventual | Select id, model, displayName   

What I'm not quite getting is that the model is blank, although it does show when using graph explorer. I can't see it under additionalProperties, so I'm confused as to why this attribute is not being returned.

If I use the code snippet in graph explorer, the code generated is slightly different.

Get-MgDevice -Search "model:Surface+Go+2" -Property "id,+model,+displayName" -ConsistencyLevel eventual   

If I copy and paste, then PowerShell gives my a sytntax error "+" is not a valid operator.

How can I get the model included in the output?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. DaveK 1,871 Reputation points
    2022-12-23T11:27:40.393+00:00

    Hi,

    I don't know if there are any differences in how Graph via explorer returns the data and in what format but to answer your question here, I've been able to get the desired output by referencing the model from the additionalProperties. I don't have any Surface Go devices on my estate but I've got some Surface Go Laptops so the query should work fine for you if you change to your model.

    Get-MgDevice -Search "model:Surface Laptop Go 2" -ConsistencyLevel eventual | Select id, @{Name="Model";Expression={$_.AdditionalProperties.model}}, displayName  
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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