Copy Members from One Distribution Group to Another with PowerShell

Listen to this Post

Featured Image
Managing distribution groups in Exchange Online can be time-consuming, especially when manually copying members between groups. Automating this task with PowerShell saves time and reduces errors. Below is a verified script to copy members and managers between distribution groups.

PowerShell Script for Copying Distribution Group Members

 Import Exchange Online module 
Import-Module ExchangeOnlineManagement

Connect to Exchange Online 
Connect-ExchangeOnline -UserPrincipalName [email protected]

Define source and target distribution groups 
$SourceGroup = "[email protected]" 
$TargetGroup = "[email protected]"

Copy members from source to target 
$Members = Get-DistributionGroupMember -Identity $SourceGroup 
$Members | ForEach-Object { 
Add-DistributionGroupMember -Identity $TargetGroup -Member $<em>.PrimarySmtpAddress 
Write-Output "Added $($</em>.PrimarySmtpAddress) to $TargetGroup" | Out-File -Append "CopyMembersLog.txt" 
}

Copy managers if needed 
$SourceManagers = (Get-DistributionGroup -Identity $SourceGroup).ManagedBy 
if ($SourceManagers) { 
Set-DistributionGroup -Identity $TargetGroup -ManagedBy @{Add=$SourceManagers} 
Write-Output "Copied managers from $SourceGroup to $TargetGroup" | Out-File -Append "CopyMembersLog.txt" 
}

Disconnect session 
Disconnect-ExchangeOnline -Confirm:$false 

You Should Know:

  • Logging: The script generates `CopyMembersLog.txt` to track changes.
  • Bulk Operations: Modify the script to loop through multiple groups if needed.
  • Error Handling: Add `Try-Catch` blocks to manage exceptions.
  • Permissions: Ensure you have Exchange Admin rights before execution.

Alternative: Using Exchange Admin Center (EAC)

  1. Go to Exchange Admin Center > Recipients > Groups.
  2. Select the source group and note its members.
  3. Open the target group and manually add members.

Expected Output:

Added [email protected] to [email protected] 
Added [email protected] to [email protected] 
Copied managers from [email protected] to [email protected] 

What Undercode Say:

Automating repetitive tasks like group management enhances efficiency. PowerShell remains the best tool for bulk operations in Exchange Online. For advanced scenarios, explore:
– Dynamic Distribution Groups: `New-DynamicDistributionGroup`
– Nested Groups: Use `Get-DistributionGroupMember -Recursive`
– Audit Logs: `Search-UnifiedAuditLog -Operations “Add-MailboxPermission”`

Prediction:

As Microsoft 365 evolves, expect more AI-driven group management features, reducing dependency on manual scripts.

Expected Output:

Script executed successfully. Members and managers copied. Log file generated. 

URL: Download the script here

References:

Reported By: Jake Admindroid – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram