Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of Get-AzureADUser [-Filter <String>] command

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.

like image 844
Sameer Avatar asked Jan 26 '17 11:01

Sameer


3 Answers

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

like image 77
juvchan Avatar answered Oct 10 '22 16:10

juvchan


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
like image 20
Sameer Avatar answered Oct 10 '22 16:10

Sameer


get-azureaduser -all $true -Filter "startswith(UserPrincipalName,'JohnAdam')"

or use variable

get-azureaduser -all $true -Filter "UserPrincipalName eq '$userPrincipalName'"
like image 27
AShah Avatar answered Oct 10 '22 16:10

AShah