Forum Discussion
Acidrs
Jul 01, 2020Copper Contributor
Wildcards using get-azureaduser
Hello, I am having a little trouble trying to query my azuread instance using powershell. I am running the follow command Get-AzureADUser -Filter "userPrincipalName eq '*@someemail....
AndySvints
Jul 02, 2020Steel Contributor
Hello Acidrs,
-Filter parameter is an oData v3.0 filter statement and do not accept wildcards(*).
You can use startswith within your filter statement bool startswith(string string, string prefixString):
Get-AzureADUser -Filter "startswith(UserPrincipalName,'Sam')"
Another option would be to use -SearchString (which also do not accept wildcards...):
Get-AzureADUser -SearchString Melissa
Please read here for more details.
To accomplish your goal you would need to get all users and then use Where-Object and -like operator:
Get-AzureADUser | Where-Object {$_.UserPrincipalName -like "*@someemail.com"}
Hope that helps.