In the last few years, Graph started to dominate on accessing/managing various products across Microsoft cloud platforms. We are starting with a series of posts related with Graph API and various techniques for IT Administrators, which could be helpful on the day today operations.
Filtering User Objects
Filter based on DisplayName
Get-MgUser -Filter "Displayname eq 'Abba'"
![](https://decodingcloud.com/wp-content/uploads/2024/10/image.png)
Filter based on Email address
Get-MgUser -Filter "mail eq 'thomas@decodingcloud.in'"
![](https://decodingcloud.com/wp-content/uploads/2024/10/image-1.png)
Filter based on starting pattern
Get-MgUser -Filter "StartsWith(DisplayName,'ab')"
![](https://decodingcloud.com/wp-content/uploads/2024/10/image-2.png)
Filter based on an attribute not equal to a specific value
Get-MgUser -Filter "displayname ne 'abba'" -ConsistencyLevel eventual -CountVariable CountVa
Note - The operator 'ne' falls under Advanced Query, Hence ConsistencyLevel and CountVariable are required.
Note - Note all properties are supported for advanced queries. Refer the official documentation for understanding the supported attributes.
![](https://decodingcloud.com/wp-content/uploads/2024/10/image-3-1024x118.png)
Filter based on an attribute ending with a specific value
Get-MgUser -Filter "endswith(UserPrincipalName,'decodingcloud.in')" -ConsistencyLevel eventual -CountVariable Count
Note - Note all properties are supported for advanced queries. Refer the official documentation for understanding the supported attributes.
![](https://decodingcloud.com/wp-content/uploads/2024/10/image-4-1024x109.png)
These MG cmdlets are to read objects based on certain conditions from Entra ID. I have included sample queries which are available by default and advanced queries which needs additional consideration. The thumb rule to understand is for query operations, It depends on
1) Understanding if the operator supports filtering based on the specific property we are trying to filter
2) Understanding if the filtering falls under an advanced filtering capability
And for Entra ID, this changes based on each object category.
Lets discuss more on advanced queries on the next blog post.