Mail-Enabled Security Groups are one of those hybrid objects in Microsoft 365 that combine permission management and email distribution in a single group.
While most of us prefer Microsoft Graph PowerShell for modern automation, there is one important limitation you must know:
β Graph PowerShell cannot create Mail-Enabled Security Groups (yet).
To create them, you must use Exchange Online PowerShell because mail-enabled security groups are fundamentally Exchange objects.
In this article, weβll walk through:
Letβs get started.
Try the M365Corner Microsoft 365 Reporting Tool β your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Mail-enabled security groups are created using the ExchangeOnlineManagement module.
Install the module
Install-Module ExchangeOnlineManagement -Scope CurrentUser
If prompted:
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline
After running this command:
To create mail-enabled security groups, you need:
Without proper roles, you will receive permission-related errors.
Letβs look at the script:
$Owners = @('owner1@domain.com', 'owner2@domain.com')
$Members = @('member1@domain.com', 'member2@domain.com')
New-DistributionGroup -Name "HR Department" -Alias "hrdepartment" -Type "Security"
-ManagedBy $Owners -Members $Members
Now letβs break this down clearly.
$Owners = @('owner1@domain.com', 'owner2@domain.com')
$Members = @('member1@domain.com', 'member2@domain.com')
New-DistributionGroup -Name "HR Department" -Alias "hrdepartment" -Type "Security" -ManagedBy $Owners -Members $Members
What each parameter does:
| Parameter | Purpose |
|---|---|
| -Name | Display name of the group |
| -Alias | Mail alias (used in SMTP address) |
| -Type Security | Converts it into a Mail-Enabled Security Group |
| -ManagedBy | Assigns group owners |
| -Members | Adds initial members |
Once executed:
This is the simplest and cleanest way to create one group.
When managing multiple departments or projects, bulk creation is far more efficient.
Here is the script:
# Import the CSV file
$groups = Import-Csv -Path "MailEnabledSecurityGroups.csv"
# Create each mail-enabled security group
foreach ($group in $groups) {
try {
New-DistributionGroup -Name $group.Name `
-Alias $group.Alias `
-PrimarySmtpAddress "$($group.Alias)@7xh7fj.onmicrosoft.com" `
-Type Security
Write-Host "β
Created: $($group.Name)" -ForegroundColor Green
} catch {
Write-Host "β Failed: $($group.Name)" -ForegroundColor Red
Write-Host $_.Exception.Message
}
}
Step 1: Import CSV
$groups = Import-Csv -Path "MailEnabledSecurityGroups.csv"
This reads group details from a CSV file.
Step 2: Loop Through Each Group
foreach ($group in $groups)
This processes each row in the CSV one by one.
Step 3: Create the Group
New-DistributionGroup -Name $group.Name `
-Alias $group.Alias `
-PrimarySmtpAddress "$($group.Alias)@7xh7fj.onmicrosoft.com" `
-Type Security
Step 4: Error Handling
If successful:
β
Created: HR Department
If failed:
β Failed: HR Department
The script also displays the actual exception message.
This makes troubleshooting much easier in large deployments.
CSV File Format
Your CSV file should look like this:
Name,Alias
HR Department,hrdepartment
Finance Team,financeteam
IT Support,itsupport
Save it as: MailEnabledSecurityGroups.csv
Place it in the same directory where you run PowerShell, or provide full path.
You can enhance this script by:
Modify CSV to include Owners column and assign using -ManagedBy.
After creation, use Add-DistributionGroupMember.
Instead of using onmicrosoft.com, use your verified domain.
Replace Write-Host with Out-File for logging.
Use: Get-DistributionGroup -Identity $group.Name to check if the group already exists before creating.
| Error | Cause | Solution |
|---|---|---|
| Insufficient Permissions | You are not assigned Exchange Administrator or Global Administrator role. | Assign required role in Entra Admin Center β Roles & Administrators. |
| The term 'New-DistributionGroup' is not recognized | Exchange Online module is not imported or connected. | Import-Module ExchangeOnlineManagement Connect-ExchangeOnline |
| ProxyAddress already exists | SMTP address is already assigned to another object. | Change alias or verify existing objects using: Get-Recipient -Filter "EmailAddresses -eq 'smtp:hrdepartment@domain.com'" |
| Object not found for ManagedBy or Members | Specified user does not exist or incorrect UPN. | Verify user existence: Get-User owner1@domain.com |
Mail-Enabled Security Groups are essential when you need: i) Centralized permission management, ii) Email distribution capability and iii) Hybrid identity and communication control.
Although Microsoft Graph PowerShell is powerful, it currently does not support creating Mail-Enabled Security Groups. For now, Exchange Online PowerShell remains the official and reliable method.
© Created and Maintained by LEARNIT WELL SOLUTIONS. All Rights Reserved.