Get Details of members of all Groups Present in Office 365 Tenant

Description:

This script is used to get all Groups, Group Members and save into CSV

Script:

Install-Module -Name AzureAD

Connect-AzureAD

Install-Module -Name Msonline

Connect-MsolService

$OutputFile = Read-Host -Prompt "Enter the path and file name for the .csv file eg. C:\users\Awais\desktop\filename.csv"  

Out-File -FilePath $OutputFile -InputObject "Group DisplayName, Group Email, Member DisplayName, Member Email" -Encoding UTF8   

$objGroups = Get-msolgroup -All | Sort-object objectid  

Foreach ($objGroup in $objGroups)   

{  write-host "Processing $($objGroup.DisplayName)..." 

$objGMembers = Get-MsolGroupMember -groupobjectid $($objGroup.objectid)

write-host "Found $($objGMembers.Count) members..."   

$name = $_.objectid 

$displayname = $_.displayname 

$email = $_.proxyaddresses   

Foreach ($objMember in $objGMembers)   

{   

Out-File -FilePath $OutputFile -InputObject "$($objGroup.DisplayName),$($objGroup.proxyaddresses),$($objMember.DisplayName),$($objMember.EmailAddress)" -Encoding UTF8 -append           

write-host "`t$($objGroup.DisplayName),$($objGroup.proxyaddresses),$($objMember.DisplayName),$($objMember.EmailAddress)"  

}}

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us