Skip to content

Instantly share code, notes, and snippets.

@LukeEvansTech
Created September 9, 2022 14:53
Show Gist options
  • Save LukeEvansTech/94559f95436de05cacb5e5deba3c1490 to your computer and use it in GitHub Desktop.
Save LukeEvansTech/94559f95436de05cacb5e5deba3c1490 to your computer and use it in GitHub Desktop.
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