Created
September 9, 2022 14:53
-
-
Save LukeEvansTech/94559f95436de05cacb5e5deba3c1490 to your computer and use it in GitHub Desktop.
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
Connect-AzureAD | |
$Groups= Get-AzureADGroup -All $true | |
$GroupMembership =@() | |
ForEach ($group in $groups){ | |
$Owners = Get-AzureADGroupOwner -ObjectId $G.Id -All:$true | |
$Members = Get-AzureADGroupMember -ObjectId $G.ID -All:$true | |
foreach ($O in $Owners) { | |
$GroupObject = [PSCustomObject]@{ | |
GroupID = $G.Id | |
GroupDisplayName = $G.DisplayName | |
UserID = $O.ObjectId | |
UserPrincipalName = $O.UserPrincipalName | |
UserDisplayName = $O.DisplayName | |
UserType = 'Owner' | |
} | |
# Add the Permissions Object to the Array | |
$GroupMembership += $GroupObject | |
} | |
foreach ($M in $Members) { | |
$GroupObject = [PSCustomObject]@{ | |
GroupID = $G.ObjectId | |
GroupDisplayName = $G.DisplayName | |
UserID = $M.ObjectId | |
UserPrincipalName = $M.UserPrincipalName | |
UserDisplayName = $M.DisplayName | |
UserType = 'Member' | |
UserEnabled = $M.AccountEnabled | |
} | |
# Add the Permissions Object to the Array | |
$GroupMembership += $GroupObject | |
} | |
} | |
$GroupMembership | Export-Csv -Encoding UTF8 -Delimiter ";" -Path "C:\scripts\output.csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment