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!
2 Answers
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!
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.
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'"

Totally agree! This is the way to go.