Skip to Content
Communication Square LLC Help Center

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

Written October 2020. Microsoft changes these admin screens often, so the screenshots below may not match what you see today. The sequence of steps is usually still correct — if something looks wrong, tell us and we'll update it.

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)"  

}}

Last updated on