Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PowerShell script to copy O365 distribution lists from a mailbox to another
# Connect to O365 via PowerShell
$Cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Cred -Authentication Basic –AllowRedirection
Import-PSSession $Session
# Copy the distribution lists
# replace with the email from which you want to copy the DL's
# replace with the email to which you want to copy the DL's
$dists= Get-DistributionGroup
$sourceMailbox = Get-Mailbox ''
foreach($dist in $dists){
$gms = Get-DistributionGroupMember -identity $dist.Identity
foreach ($gm in $gms){
if ($ -eq ${
write-host 'User Found In Group' $dist.Alias
Add-DistributionGroupMember -Identity $dist.Alias -Member ""
# Disconnect from O365
Remove-PSSession $Session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment