How to Properly Filter MS Graph Requests for Devices?

April 8, 2026 2 answers
Asked by Errata
Hey everyone! I'm working on fetching a list of devices from MS Graph. I've managed to get some filtering to work, but I'm having trouble filtering out devices that aren't running Windows. I'm not sure what I'm doing wrong. Here's a sample of my query and the results I'm getting: $a = invoke-mggraphrequest -uri "https://graph.microsoft.com/v1.0/devices/?$top=999$filter=operatingSystem eq 'Windows'" $a.value.operatingSystem Windows AndroidEnterprise Windows Windows IPad Windows Windows AndroidEnterprise Android Any help would be appreciated!

Answers

4L pressure cooker
It looks like you need to escape your `$` signs in the double-quoted string and add an `&` before your filter. Try this: $a = Invoke-MgGraphRequest -uri "https://graph.microsoft.com/v1.0/devices/?`$top=999&`$filter=operatingSystem eq 'Windows'"
Reply to this answer
CoDe-switch
Consider using the SDK directly instead of the REST request. It follows the usual PowerShell conventions: Get-MgDevice -Top 1000 -Filter {operatingSystem eq "Windows"} This approach simplifies things and can save you some trouble!

Drix: Totally agree! This is the way to go.

Tuppence: Also, if you're looking for specific commands, try using Find-MgGraphCommand with the /v1.0/devices endpoint. You can also check out [aka.ms/ge](http://aka.ms/ge) for useful code snippets.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions