How can I filter Get-AzureADUser for two values?
So for the following I can search for DisplayName starts with Student but I also want to return values where UserPrincipalName also contains "@somedomain.com"
Get-AzureADUser -Filter "startswith(DisplayName,'student')"
I don't think this can be done with -Filter
only. Since the oData v3 filters don't support operators (using match
or like
) that do partial matching, you have to rely on built-in functions. It appears you can't use the endswith()
or substringof()
function in -Filter
. You'd need to resort to Where-Object
to filter further.
Get-AzureADUser -Filter "startswith(DisplayName,'student')" -All:$true |
Where UserPrincipalName -like '*@somedomain.com'
I tested multiple scenarios using the Azure Cloud shell.
# Error
Get-AzureADUser -Filter "startswith(displayname,'student') and endswith(displayname,'student')"
# Error
Get-AzureADUser -Filter "startswith(displayname,'student') and endswith(UserPrincipalName,'@domain.com')"
# Error
Get-AzureADUser -Filter "(startswith(displayname,'student')) and (endswith(UserPrincipalName,'@domain.com'))"
# Error
Get-AzureADUser -Filter "endswith(UserPrincipalName,'@domain.com')"
# Error
Get-AzureADUser -Filter "substringof('@domain.com',UserPrincipalName)"
# No Errors
Get-AzureADUser -Filter "startswith(displayname,'student') and startswith(UserPrincipalName,'student')"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.