1 minute reading time (271 words)

Get members of an Azure AD group using PowerShell Get-AzureADGroupMember and export to CSV

How to get members of an Azure AD group using PowerShell Get-AzureADGroupMember and export to CSV

Azure AD groups can be managed using the AzureADGroup and AzureADGroupMember PowerShell cmdlets. These cmdlets get group information via AzureAD Graph.

Before you begin

# Connect to Azure AD
Connect-AzureAD 

Get-AzureADGroupMember limited to 100 results

When running Get-AzureADGroupMember from Azure cloud shell, the results are limited to 100 unless you specify either the -All or -Top option.

-All $true return all group members
-Top n specify the number of results to return

Example: Get-AzureADGroupMember -All

Get-AzureADGroup -ObjectId df095002-f3ae-9077-6720-3a095edd8ff4 | Get-AzureADGroupMember -All $True 

Example: Get-AzureADGroupMember -Top

Get-AzureADGroup -ObjectId df095002-f3ae-9077-6720-3a095edd8ff4 | Get-AzureADGroupMember -Top 50 

List all Azure AD groups using PowerShell Get-AzureADGroup

Get-AzureADGroup -All $true 

Get Azure AD groups using a search string

This example will get all groups that have the text "All Staff" in their display names.

Get-AzureADGroup -SearchString "All Staff" 

Get Azure AD groups using a filter

In this example, using -Filter will return an exact match.

Get-AzureADGroup -Filter "DisplayName eq 'All UK Staff'" -All $true 

Get Azure AD group members and export to CSV

# define variable for aad  group
$AADGroup = "All UK Staff"

# get Azure AD Group members and export to CSV
Get-AzureADGroup -SearchString $AADGroup | Get-AzureADGroupMember | Select DisplayName, Mail | Export-Csv -path "c:\temp\$AADGroup-members-$((Get-Date).ToString('dd-MM-yyyy')).csv" 

References:

Azure Active Directory PowerShell - Get-AzureADGroup
https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureadgroup

Azure Active Directory PowerShell - Get-AzureADGroupMember
https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureadgroupmember

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Saturday, 23 September 2023
You can help support this website by buying me a coffee!
Buy Me A Coffee