How to Use New-MgGroup to Create Microsoft 365 Groups?

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.

What is New-MgGroup?

New-MgGroup is a cmdlet in the Microsoft Graph PowerShell SDK that allows administrators to create new groups in Microsoft 365, including:

  • Security groups
  • Microsoft 365 Groups (Unified groups)
  • Mail-enabled groups

It replaces the older AzureAD module and leverages the Graph API under the hood.

Why Use New-MgGroup?

Using New-MgGroup gives you:

  • Automation for bulk group creation.
  • Flexibility to define group types (Security or Unified).
  • Custom attributes such as mail nickname, description, and settings.
  • Integration with scripts, CSVs, and workflows.

Cmdlet Syntax

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.

Usage Examples

Create a Security Group

This creates a mail-disabled security group commonly used for assigning permissions:

New-MgGroup -DisplayName "Security Group XXX" `
    -MailNickname "SecGroupXXX" `
    -SecurityEnabled `
    -MailEnabled:$false

Create an Office 365 Group (Unified Group)

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

Creating Multiple Office 365 Groups by Reading Data from a CSV File

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
}

Sample CSV Format (Groups.csv)

DisplayName,MailNickname,Description
Sales Team,sales.team,Group for the Sales Department
Marketing Team,marketing.team,Marketing Collaboration Group

Frequently Asked Questions


What’s the difference between a Security Group and a Unified Group?

  • Security Group: Used for permission and access control.
  • Unified Group (Microsoft 365 Group): Designed for collaboration with shared mailbox, calendar, SharePoint, and Teams.

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:

  • MailNickname is unique and doesn’t contain special characters.
  • GroupTypes is set as an array (e.g., @("Unified")), not just a string.

Use Cases

  • Permission Management: Create security groups for role-based access control.
  • Team Collaboration: Set up Office 365 Groups for departments like Sales, HR, etc.
  • Automation Workflows: Create groups dynamically from user or department data.
💡 Use -BodyParameter for Consistent Bulk Creation

For large-scale provisioning or template-based group creation, using -BodyParameter @{...} ensures each attribute is cleanly applied across bulk operations. This approach minimizes typo errors and keeps your scripts maintainable.
⚠️ Always Verify MailNickname for Uniqueness

MailNickname 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.

Conclusion

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