9

Command: Get-AzureADUser [-Filter ] command

msdn says Parameters -Filter Specifies an oData v3.0 filter statement. This parameter controls which objects are returned.

how to set filter to get the same result as Azure module v1 commands

Get-MsolUser -All| Where-Object {$_.isLicensed -eq "True"}| Select-Object UserPrincipalName -ExpandProperty Licenses|Select-Object UserPrincipalName -ExpandProperty ServiceStatus|Where-Object {$_.ProvisioningStatus -eq "Success" -and $_.ServicePlan.ServiceName -like "MCO*"}|select UserPrincipalName -Unique

I have searched all over the place to find a proper example of setting filter but could not and i ended up here. I am basically trying to convert my Azure module v1 commands to Azure module v2 commands.

Sameer
  • 3,124
  • 5
  • 30
  • 57

4 Answers4

10

A few examples of Get-AzureADUser [Filter] command are as below:

Get-AzureADUser -Filter "DisplayName eq 'Juv Chan'"
Get-AzureADUser -Filter "DisplayName eq 'Juv Chan' and UserType eq 'Member'"

This is following the oData 3.0 Filter semantics as specified here.

Note that the Get-AzureADUser cmdlet is only returning 4 fields:

Object Id, Display Name, UserPrincipalName, UserType

Hence, it is not possible to create an equivalent v2 command using the cmdlet above for your v1 command above.

The version of AzureAD PowerShell v2 module tested for the above is 2.0.0.33. https://www.powershellgallery.com/packages/AzureAD/2.0.0.33

juvchan
  • 6,113
  • 2
  • 22
  • 35
  • 2
    Get-AzureADUser returns all fields available in graph.windows.net. Please try running the `Get-AzureADUser` result through `Format-List`. `Get-AzureADUser -Filter "DisplayName eq 'Juv Chan'"|Format-List` – Zacharious Feb 13 '17 at 23:44
  • 1
    +1 just for having a working filter query. You'd be surprised at how hard it is to find an example of that! – Rolan Apr 01 '21 at 15:15
  • Does it means that the -Filter is not the same as the Get-ADuser -Filter format ? – Senior Systems Engineer Feb 21 '23 at 02:20
2
get-azureaduser -all $true -Filter "startswith(UserPrincipalName,'JohnAdam')"

or use variable

get-azureaduser -all $true -Filter "UserPrincipalName eq '$userPrincipalName'"
AShah
  • 846
  • 2
  • 17
  • 33
1

This seems to do it

Get-AzureADUser -All $true|select UserPrincipalName -ExpandProperty AssignedPlans|Where-Object {$_.CapabilityStatus -eq "Enabled" -and $_.Service -eq "MicrosoftCommunicationsOnline"} |select UserPrincipalName -Unique
Sameer
  • 3,124
  • 5
  • 30
  • 57
0

Here's a createddatetime one. The double quotes have to be on the outside, and the date has to be in that format.

Get-AzureADUser -Filter "createddatetime ge datetime'2023-04-13'"

These fields are unrecognized:

get-azureaduser -filter "CapabilityStatus eq 'Enabled' and service eq 'MicrosoftCommunicationsOnline'"

get-azureaduser : Error occurred while executing GetUsers
Code: Request_UnsupportedQuery
Message: Property 'CapabilityStatus' does not exist as a declared property or extension property.

Can I access something like "signInActivity/lastSignInDateTime"?

js2010
  • 23,033
  • 6
  • 64
  • 66