Azure AD group membership PowerShell

In this Azure tutorial, we will discuss Azure AD group membership PowerShell. Apart from this, we will also discuss on the below topics

Azure AD group membership PowerShell

We can use Get-AzureADGroupMember to get Azure AD group members using PowerShell.

Get-AzureADGroupMember

You can use this Azure PowerShell command to get Azure AD group members.

Syntax:

Get-AzureADGroupMember
   -ObjectId <String>
   [-All <Boolean>]
   [-Top <Int32>]
   [<CommonParameters>]

Parameters

-All

If the value is true, return all group members. If the value is false, return the number of objects

-ObjectId

It specifies the ID of a group in Azure AD to which the user belongs to.

-Top

It shows the maximum number of records to return.

Get-AzureADGroupMember Examples

You can use the command below to get the member details from the group in Azure active directory.

PS C:\windows\system32> Get-AzureADGroupMember

Once you execute the above command, it will ask you to enter the ObjectID (The ID of the AD group to which the user belongs)

get-azureadgroupmember

Now enter the ObjectId, then run, and the output will be as below.

ObjectId                             DisplayName UserPrincipalName                 UserType
--------                             ----------- -----------------                 --------
ee09bfcd-36e9-47c2-a98c-cf19412540e6 Bks Sahoo   bks@SPSkyTraining.onmicrosoft.com Member 

You can check out the below screenshot to see the same output.

powershell azure ad group membership

You can also use the command in the below format.

PS C:\windows\system32> Get-AzureADGroupMember -ObjectId "23359f6d-850e-47e3-96b3-6ccae2ecb7bd"

You can mention the ObjectId with the Get-AzureADGroupMember command inline.

powershell get azure ad group members

Output will be

ObjectId                             DisplayName UserPrincipalName                 UserType
--------                             ----------- -----------------                 --------
ee09bfcd-36e9-47c2-a98c-cf19412540e6 Bks Sahoo   bks@SPSkyTraining.onmicrosoft.com Member  

Note:

Before running the above commands, You need to connect to Azure using the below command

PS C:\windows\system32> Connect-AzureAD
azure ad group membership powershell

PowerShell command to get Azure ad group members

If you want to get the existing members belonging to a group, you can use the Get-AzureADGroupMember command.

The syntax is

Get-AzureADGroupMember -ObjectId <String> [-All <Boolean>] [-Top <Int32>] [<CommonParameters>]
 PS C:\Windows\system32> Get-AzureADGroupMember -ObjectId 219b773f-bc3b-4aef-b320-024a2eec0b5b

The output will be

ObjectId                             DisplayName UserPrincipalName                 UserType
--------                             ----------- -----------------                 --------
ee09bfcd-36e9-47c2-a98c-cf19412540e6 Bks Sahoo   bks@SPSkyTraining.onmicrosoft.com Member  
get azure group members

PowerShell command to remove Azure AD group members

You can remove the member we previously added to the group. We can use the Remove-AzureADGroupMember.

PS C:\Windows\system32> Remove-AzureADGroupMember -ObjectId f21bae22-8ac0-780c-bc37-udae0f3da61i -MemberId ee09bfcd-36e9-47c2-a98c-cf19412540e6

You may like the following Azure tutorials:

Conclusion

In this Azure tutorial, We discussed the steps to get Azure AD group members using PowerShell.