Last active
September 18, 2023 23:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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