How to Export Groups and Members via Powershell

This guide shows you how to export a list of all Distribution and Security groups on your Office 365 as well as members of each group using Powershell.

First Open up PowerShell ad Administrator and type the following commands:

Step 1:
The below command specifies where the .csv file will be saved

Constant Variables

$OutputFile = “C:/users/user name/desktop/test.csv” #The CSV Output file that is created, change for your purposes
$arrDLMembers = @{}

Step 2:

Remove all existing Powershell sessions

Get-PSSession | Remove-PSSession

Step 3:
This command connects you to O365, please enter your o365 admin credentials as shown below:

Create remote Powershell session

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Office365credentials -Authentication Basic –AllowRedirection

Last updated on 22 Mar 2022
2608 reads
Tell us what you think?00