I'm using PowerShell to connect to Azure AD. I need to get a list of specific users whose accounts are not in a particular team.
To enter my tenant, I used cmdlet Connect-AzureAD. To get users I have to use the cmdlet Get-AzureADUser. I'm using -Filter along with it to get a list of those specific users.
I'm using a cmdlet like this:
Get-AzureADUser -Filter "Team ne 'Development' "
But I'm getting an error like this:
Get-AzureADUser : Error occured while executing GetUsers
Code: Request_UnsupportedQuery
HttpStatusCode : BadRequest
HttpStatusDescription: BadRequest
HttpResponseStatus: Completed
What am I doing wrong? Can anyone help me out
CodePudding user response:
I tested in my environment. I also got same error.
This error usually occurs because depending on PowerShell version, Get-AzureADUser won’t support ne(not equal to) operator and Team attribute with Filter statement.
Instead of Team attribute, you can make use of Department.
Only the following operators are supported by Get-AzureADUser filter parameter based on version.
- eq - equals to
- and - including both
- or - either first or second
- startswith - String starts with
To filter the list of users by eq operator worked.
Get-AzureADUser -Filter "Department eq 'IT"
The output will be like this:
Please check below workarounds if they are helpful.
- You can try using
andoperator by including all departments other than "Development". - Otherwise, you can update the versions and try again.


