Advertisement
Xology

Untitled

Jan 30th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1.  
  2.  
  3. Class GroupList {
  4.  
  5. [string]$GroupName
  6. [string]$GroupObjectID
  7.  
  8.  
  9. }
  10.  
  11. Class GroupListMembers {
  12.  
  13. [string]$GroupName
  14. [string]$GroupObjectID
  15. [array]$GroupMembersip
  16.  
  17.  
  18. }
  19.  
  20. $grouplistResults = [System.Collections.Generic.List[object]]::new()
  21.  
  22. foreach ($user in $users) {
  23. $groups = Get-AzureADUserMembership -ObjectId $User
  24.  
  25. foreach ($Group in $groups) {
  26. $GroupList = [GroupList]::New()
  27. $grouplist.GroupName = $group.displayname
  28. $grouplist.GroupObjectID = $group.ObjectID
  29.  
  30. [void]$grouplistResults.Add([PSCustomObject]$GroupList)
  31. }
  32. }
  33.  
  34.  
  35. $groupMembershipResults = [System.Collections.Generic.List[object]]::new()
  36.  
  37. foreach ($group in $grouplistResults | select GroupName, GroupObjectID -Unique ) {
  38. write-host "Processing: $($group.GroupName) - ($($group.GroupObjectID))"
  39. if ($null -ne $($group.GroupObjectID)) {
  40. $groupinfo = Get-AzureADGroup -ObjectId $group.GroupObjectID
  41. $groupmembership = Get-AzureADGroupMember -ObjectId $group.GroupObjectID
  42.  
  43. $GroupResults = [GroupListMembers]::New()
  44. $GroupResults.GroupName = $Group.GroupName
  45. $GroupResults.GroupObjectID = $Group.GroupObjectID
  46. $GroupResults.GroupMembersip = $groupmembership
  47.  
  48. [void]$groupMembershipResults.Add([PSCustomObject]$GroupResults)
  49.  
  50. } else {
  51. write-host "Skipping Exchange Group DL " -ForegroundColor Yellow
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement