Microsoft 365 Groups are essential for enabling collaboration across organizations. Whether you’re setting up a Team in Microsoft Teams, configuring a shared mailbox in Exchange Online, or creating a SharePoint site, groups form the foundation of seamless teamwork and resource sharing.
While the Microsoft 365 Admin Center offers an interface for creating groups, the process can be time-consuming, especially for bulk operations. The New-MgGroup cmdlet, part of the Microsoft Graph PowerShell module, provides a more efficient way to create and manage groups programmatically.
This guide will help you understand and use New-MgGroup effectively, with step-by-step instructions and examples.
Microsoft 365 Groups are a cross-application membership service. They bring together people, information, and resources, providing access to shared tools like:
A Microsoft 365 Group automatically provisions these resources, making it easier for teams to collaborate without the need for additional setup.
The New-MgGroup cmdlet allows administrators to:
By using New-MgGroup, you can streamline workflows and reduce the chances of errors associated with manual group creation.
To use New-MgGroup, you’ll need to install and configure the Microsoft Graph PowerShell module:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.ReadWrite.All"
You will be prompted to log in with your admin credentials.
Disconnect-MgGraph
To create a single Microsoft 365 group with basic attributes:
New-MgGroup -DisplayName "test8811" -MailNickname "test8811" -GroupTypes "Unified" -MailEnabled:$false -SecurityEnabled:$false
This creates a Microsoft 365 group named “test8811” with email functionality enabled.
To create multiple groups in one script, define their details in an array and iterate through it:
$groups = @( @{ DisplayName="HR Team 1220"; MailNickname="hrteam1220"; }, @{ DisplayName="Sales Team 1220"; MailNickname="salesteam1220"; } ) foreach ($group in $groups) { New-MgGroup -DisplayName $group.DisplayName -MailNickname $group.MailNickname -MailEnabled:$true -GroupTypes @("Unified") -SecurityEnabled:$false }
This script creates multiple groups programmatically.
For bulk group creation, import data from a CSV file.
$groups = Import-Csv -Path "C:\Groups.csv" foreach ($group in $groups) { New-MgGroup -DisplayName $group.DisplayName -MailNickname $group.MailNickname -MailEnabled:$true -GroupTypes @("Unified") -SecurityEnabled:$false }
This script reads group details from the CSV file and creates them automatically.
New-MgGroup -DisplayName "Dev Team" -MailNickname "devteam" -MailEnabled:$true -GroupTypes @("Unified") -Visibility "Private" -Description "Development team working on internal projects"
$groupId = (New-MgGroup -DisplayName "Support Team" -MailNickname "supportteam" -MailEnabled:$true -GroupTypes @("Unified") -SecurityEnabled:$false).Id New-MgGroupMember -GroupId $groupId -DirectoryObjectId "user-id"
New-MgGroup -DisplayName "Test Group" -MailNickname "testgroup" -MailEnabled:$true -GroupTypes @("Unified") -SecurityEnabled:$false -WhatIf
The New-MgGroup cmdlet is an invaluable tool for Microsoft 365 administrators, enabling efficient and automated group creation. By mastering New-MgGroup, you can enhance productivity, ensure consistency, and maintain better control over your Microsoft 365 environment.
By mastering New-MgGroup, you can enhance productivity, ensure consistency, and maintain better control over your Microsoft 365 environment. Start scripting today and take your group management to the next level!
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.
© M365Corner. All Rights Reserved.