Creating and managing groups is an essential part of Microsoft 365 administration. Groups help organize teams, control access to resources, and streamline collaboration. With Microsoft Graph PowerShell, you can easily create, customize, and manage Microsoft 365 (Office 365) groups using the New-MgGroup cmdlet.
In this article, we’ll walk through three practical PowerShell scripts that use New-MgGroup to create Office 365 groups. Each example is simple, easy to understand, and perfect for beginners who want to automate group creation in Microsoft 365.
Before running these scripts, make sure you have installed and connected to the Microsoft Graph PowerShell module:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.ReadWrite.All"
Once connected, you can start creating Office 365 groups using the following scripts.
New-MgGroup -DisplayName "Office 365 Group 1" -MailNickname "O365Group1" -GroupTypes "Unified" -MailEnabled:$true
Explanation:
This command creates a new Microsoft 365 (Unified) group named Office 365 Group 1 with the mail nickname O365Group1.
This is the most common way to create collaboration-ready groups for Teams, Outlook, and SharePoint.
New-MgGroup -DisplayName "Security Group 1" -MailNickname "SecGroup1" -SecurityEnabled -MailEnabled:$false
Explanation:
This command creates a new Microsoft 365 Security group named Security Group 1 with the mail nickname O365Group1.
You can create multiple Office 365 groups at once by reading group details from a CSV file. Here’s how you can do it:
CSV File Example
DisplayName,MailNickname,Description
HR Team 1000,HRTeam1000,Group for HR 1000 department
Sales Team 1000,SalesTeam1000,Group for Sales 1000 department
IT Team 1000,ITTeam1000,Group for IT 1000 department
Script
$groups = Import-Csv -Path "C:\Path\To\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
}
Explanation:
This script imports a list of groups from a CSV file and creates them in Microsoft 365 automatically.
Use Case: This is especially useful when you’re onboarding new teams, departments, or projects that require multiple groups at once.
| Error | Cause | Solution |
|---|---|---|
| Insufficient privileges to complete the operation | Missing permissions | Connect using Connect-MgGraph -Scopes "Group.ReadWrite.All" |
| Group already exists | Duplicate DisplayName or MailNickname | Use unique names for each group |
| Invalid MailNickname | Contains spaces or special characters | Use simple, alphanumeric nicknames |
The New-MgGroup cmdlet makes group creation in Microsoft 365 both simple and scalable. Whether you’re setting up a single group or provisioning dozens at once from a CSV file, these examples help streamline the process and save valuable time.
With PowerShell automation, you can focus more on managing collaboration and less on repetitive setup tasks — making your administration more efficient and error-free.
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