Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class GroupList {
- [string]$GroupName
- [string]$GroupObjectID
- }
- Class GroupListMembers {
- [string]$GroupName
- [string]$GroupObjectID
- [array]$GroupMembersip
- }
- $grouplistResults = [System.Collections.Generic.List[object]]::new()
- foreach ($user in $users) {
- $groups = Get-AzureADUserMembership -ObjectId $User
- foreach ($Group in $groups) {
- $GroupList = [GroupList]::New()
- $grouplist.GroupName = $group.displayname
- $grouplist.GroupObjectID = $group.ObjectID
- [void]$grouplistResults.Add([PSCustomObject]$GroupList)
- }
- }
- $groupMembershipResults = [System.Collections.Generic.List[object]]::new()
- foreach ($group in $grouplistResults | select GroupName, GroupObjectID -Unique ) {
- write-host "Processing: $($group.GroupName) - ($($group.GroupObjectID))"
- if ($null -ne $($group.GroupObjectID)) {
- $groupinfo = Get-AzureADGroup -ObjectId $group.GroupObjectID
- $groupmembership = Get-AzureADGroupMember -ObjectId $group.GroupObjectID
- $GroupResults = [GroupListMembers]::New()
- $GroupResults.GroupName = $Group.GroupName
- $GroupResults.GroupObjectID = $Group.GroupObjectID
- $GroupResults.GroupMembersip = $groupmembership
- [void]$groupMembershipResults.Add([PSCustomObject]$GroupResults)
- } else {
- write-host "Skipping Exchange Group DL " -ForegroundColor Yellow
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement