Microsoft 365 Groups are the backbone of collaboration across Microsoft Teams, Outlook, SharePoint, and other M365 services. Whether you're creating a security group or a collaborative Office 365 Group (also known as a unified group), the New-MgGroup cmdlet from Microsoft Graph PowerShell offers a powerful and flexible way to automate the process.
Let’s walk through how you can use New-MgGroup to create Microsoft 365 Groups, with clear examples and practical use cases.
New-MgGroup is a cmdlet in the Microsoft Graph PowerShell SDK that allows administrators to create new groups in Microsoft 365, including:
It replaces the older AzureAD module and leverages the Graph API under the hood.
Using New-MgGroup gives you:
New-MgGroup -DisplayName <String> -MailNickname <String> [-SecurityEnabled] [-MailEnabled] [-GroupTypes <String[]>] [-Description <String>]
💡 For advanced scenarios and bulk creation, use the -BodyParameter switch with a hashtable of values.
This creates a mail-disabled security group commonly used for assigning permissions:
New-MgGroup -DisplayName "Security Group XXX" `
-MailNickname "SecGroupXXX" `
-SecurityEnabled `
-MailEnabled:$false
This creates a Microsoft 365 Group, ideal for collaborative features like Teams and Outlook:
New-MgGroup -DisplayName "Office 365 Group YYY" `
-MailNickname "O365GroupYYY" `
-GroupTypes "Unified" `
-MailEnabled:$true `
-SecurityEnabled:$false
For bulk group creation, prepare a CSV file and automate the process:
$groups = Import-Csv -Path "C:\\Users\\Desktop\\Groups.csv"
foreach ($group in $groups) {
$groupParams = @{
DisplayName = $group.DisplayName
MailNickname = $group.MailNickname
Description = $group.Description
GroupTypes = @("Unified")
MailEnabled = $true
SecurityEnabled = $false
}
New-MgGroup -BodyParameter $groupParams
}
DisplayName,MailNickname,Description
Sales Team,sales.team,Group for the Sales Department
Marketing Team,marketing.team,Marketing Collaboration Group
What’s the difference between a Security Group and a Unified Group?
Can I add members while creating the group?
No, New-MgGroup only creates the group. You’ll need to use Add-MgGroupMember or Add-MgTeamMember to add members afterward.
Why do I get an error about MailNickname or GroupTypes?
Ensure:
-BodyParameter
for Consistent Bulk Creation-BodyParameter @{...}
ensures each attribute is cleanly applied across bulk operations.
This approach minimizes typo errors and keeps your scripts maintainable.
MailNickname
for UniquenessMailNickname
must be unique across your tenant and cannot contain special characters or spaces.
Failing to validate this upfront often leads to silent failures or group creation errors.
Consider pre-checking the CSV or list of nicknames before running the script.
The New-MgGroup cmdlet is a powerful tool to create Microsoft 365 Groups programmatically. Whether you're provisioning one group or hundreds, using PowerShell with Graph API gives you speed, precision, and scalability.
Explore more Microsoft Graph scripts and tutorials at M365Corner.com — your go-to resource for Microsoft 365 automation!
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex