Skip to content

Instantly share code, notes, and snippets.

@aabundez
Last active September 18, 2023 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aabundez/23369753c1f121f7ba3cf1cbc38cb612 to your computer and use it in GitHub Desktop.
Save aabundez/23369753c1f121f7ba3cf1cbc38cb612 to your computer and use it in GitHub Desktop.
This Powershell script lists all of the members of an Azure AD group
<#
.DESCRIPTION
This script returns the group members for a single group.
.LINK
https://learn.microsoft.com/en-us/powershell/module/azuread/get-azureadgroup?view=azureadps-2.0
https://learn.microsoft.com/en-us/powershell/module/azuread/get-azureadgroupmember?view=azureadps-2.0
#>
# 1) Uncomment and and run the first time you run this script
#Install-Module -Name AzureAD
# 2) Login when prompted with your AAD account that is in the same domain as the group your looking up
Connect-AzureAD
# 3) CHANGE THE GROUP NAME BELOW
$groupName = 'SomeGroupName'
# 4) Display the members of the group:
$ps = Get-AzureADGroup -SearchString $groupName
$groupId = $ps.ObjectId
Get-AzureADGroupMember -ObjectId $groupId
# 5) Export to CSV
Get-AzureADGroupMember -ObjectId $groupId | Export-Csv -NoTypeInformation "C:\Users\johndoe\Downloads\group_members.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment