How to Properly Filter MS Graph Requests for Devices?

0
4
Asked By TechSavvy99 On

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

Answered By GraphGuru77 On

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!

HelpfulTechie -

Totally agree! This is the way to go.

WindowsWhiz -

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.

Answered By CoderDude42 On

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'"

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.