Skip to main content

Microsoft 365 Admin - Use PowerShell to Add Mailboxes to a Group in Bulk

If you manage a large number of mailboxes, these scripts let you add them to a group in bulk rather than one at a time.

Important: SigParser scans individual mailboxes — it cannot scan mailboxes added through a distribution group. To use admin-level scanning, mailboxes must be added to a mail-enabled security group that you've connected to SigParser. The scripts below will help you populate that group efficiently.

Option 1: All Mailboxes with Powershell to a Mail Enabled Security Group

Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Repository PSGallery -Force

Connect-ExchangeOnline

$group = "MySecurityGroup@contoso.com"
$users = @(
"alice@contoso.com",
"bob@contoso.com",
"carol@contoso.com"
)

foreach ($user in $users) {
Add-DistributionGroupMember -Identity $group -Member $user
}

Option 2: Add mailboxes from a file to a mail-enabled security group

Create a plain text file with one email address per line, then run the script below. Update the file path and group name before running.

# Requires the ExchangeOnlineManagement module
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Repository PSGallery -Force

Connect-ExchangeOnline

# Update this path to point to your text file (one email address per line)
$filePath = "C:\Users\you\Desktop\users.txt"

# Update this to the name or email address of your mail-enabled security group
$groupIdentity = "SigParser Mailboxes"

foreach ($line in Get-Content $filePath) {
# https://docs.microsoft.com/en-us/powershell/module/exchange/add-distributiongroupmember
Add-DistributionGroupMember -Identity $groupIdentity -Member $line
Write-Output "Added: $line"
}


Did this answer your question?