Forum Discussion
Melbatoast
May 08, 2024Copper Contributor
Migrating from Get-AzureADUser to Get-MgUser
I am attempting to replicate a Get-AzureADUser command using Get-MgUser. The previous command (Get-AzureADUser -Top 5000 | Where-Object {($.AccountEnabled -eq "True") -and (($.CompanyName -eq "CompA"...
- May 09, 2024The example above works just fine in PowerShell, too:
Get-MgUser -Filter "companyName ne null and (companyName eq 'ZZZ' or companyName eq 'YYY')" -ConsistencyLevel eventual -CountVariable count
Again, use consistencyLevel/count.
VasilMichev
May 08, 2024MVP
For generic guidance, you can try this tool: https://graphpowershell.merill.net/
For the specific example, use Filter:
https://graph.microsoft.com/beta/users?$filter=(companyName ne null and (companyName eq 'ZZZ' or companyName eq 'YYY'))
Also, when using advanced queries/ConsistencyLevel, you must use $count=true (-CountVariable blabla) as well.
For the specific example, use Filter:
https://graph.microsoft.com/beta/users?$filter=(companyName ne null and (companyName eq 'ZZZ' or companyName eq 'YYY'))
Also, when using advanced queries/ConsistencyLevel, you must use $count=true (-CountVariable blabla) as well.
Melbatoast
May 08, 2024Copper Contributor
Thank you for the suggestion. The reason I resorted to the -Search option for the CompanyName field is I cannot get -Filter to recognize CompanyName. If I dumb the query down to:
Get-MgUser -All -Filter "DisplayName eq 'First Last'"
it works. If I replace the filter with this:
Get-MgUser -All -Filter "CompanyName eq 'CompA'"
I get this error:
Unsupported or invalid query filter clause specified for property 'companyName'
It seems Company Name can only be used with the -Search option. Thoughts?
- VasilMichevMay 09, 2024MVPThe example above works just fine in PowerShell, too:
Get-MgUser -Filter "companyName ne null and (companyName eq 'ZZZ' or companyName eq 'YYY')" -ConsistencyLevel eventual -CountVariable count
Again, use consistencyLevel/count.- MelbatoastMay 09, 2024Copper ContributorThank you! Adding the -CountVariable option worked. As for the other part of my question (which wound up weird because I think this site removed my fake email address and replaced it with a message), I'm not sure what happened a few days ago. Both commands now match.