It’s been a while since I have posted and wanted to share some queries I’m using for Azure AD to collect information. As an Active Directory Admin, I have spent a lot of time with the active directory PowerShell module and I’ve been finding the Microsoft Online and AzureAD PowerShell module’s to be at times frustrating in comparison. One of the more frustrating things that I have found with the new AzureAD module is the syntax around filtering and the lack of examples. Hopefully I can clear things up a little or at least give a few useful examples.
Here is why this can be frustrating.
At the time of writing this the azuread module version is 220.127.116.11
Normal PowerShell operators and syntax are different because you need to be familiar with using filters Expressions in OData. However it does not appear that all expressions are available.
“userprincipalname –eq ‘email@example.com’”
“userprincipalname eq ‘firstname.lastname@example.org’”
This doesn’t seem to be a big change but something that seems to be lacking is the ability to use a wildcard on any attribute.
“userprincipalname –like “*@contoso.com”
I would expect this to work instead but it does not:
Here is a couple of tries for queries that don’t work.
The only one I was able to get work is the following with various attributes and not sure if it provides much value though I would really like to have the substringof capability.
The cmdlets seem to only accept a few of the expressions outlined in the ODATA article, the only ones that do are the ones kind of highlighted here.
Here is some samples of queries I have put together:
Get a list of disabled users.
Get a list of Guest Users
Get a list of Role Members.
Get a list of in cloud only accounts
And last store all users in an Array and use the Where-Object
This last query isn't the greatest way of doing this. If the plan is to perform multiple queries or filtering on different attributes it will probably be easier to query every user and property and store them in an array. Once the array is populated pipe the array to a where-object to be able to perform any kind of filter needed. Keep in mind in large environments it will take some time to populate or repopulate the array.
This is really all I have for now. I will try my best to add more to this as I continue to figure out what works and doesn’t work. Hopefully in the near future the management pack will get updated again with additional capabilities.
Kind of usefulish resources