> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.accessorange.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# ## Description:

Articles on: [Scripts](/en/category/scripts-if12k0/)

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

Updated on: 31/01/2023