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

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.

Frequently Asked Questions

  • What is New-MgGroup used for?
    New-MgGroup is a Microsoft Graph PowerShell cmdlet used to create Microsoft 365 groups. It allows specifying properties like display name, mail nickname, group type, and membership settings.
  • How can I create a new Microsoft 365 group?
    Use the following script to create a group:
    $Body = @{
    displayName = "New Group Name"
    mailNickname = "NewGroup"
    groupTypes = @("Unified")
        mailEnabled = $true
        securityEnabled = $false
    }
    New-MgGroup -BodyParameter $Body
  • Can I create multiple groups using a CSV file?
    Yes, prepare a CSV file with the following format:
    DisplayName,MailNickname,MailEnabled,SecurityEnabled
    Group 1,Group1,$true,$false
    Group 2,Group2,$true,$false

    Use this script to process the CSV and create groups:
    $Groups = Import-Csv -Path "C:\Path\To\File.csv"
    foreach ($Group in $Groups) {
    $Body = @{
        displayName = $Group.DisplayName
        mailNickname = $Group.MailNickname
        mailEnabled = [bool]::Parse($Group.MailEnabled)
        securityEnabled = [bool]::Parse($Group.SecurityEnabled)
        groupTypes = @("Unified")
    }
    New-MgGroup -BodyParameter $Body
    }
  • What permissions are required to create Microsoft 365 groups?
    You need the Group.ReadWrite.All permission in Microsoft Graph PowerShell. Ensure the appropriate delegated or application permissions are granted.
  • How can I add owners to a Microsoft 365 group during its creation?
    While the New-MgGroup cmdlet does not directly support adding owners during group creation, you can assign owners afterward using the New-MgGroupOwner cmdlet. Here's how
    $groupParams = @{
        DisplayName = "Project Team"
        MailNickname = "projectteam"
        GroupTypes = @("Unified")
        MailEnabled = $true
        SecurityEnabled = $false
    }
    $group = New-MgGroup -BodyParameter $groupParams
    
    
    # Add an owner to the group
    New-MgGroupOwner -GroupId $group.Id -DirectoryObjectId "<OwnerObjectId>"
    
  • Can I create a dynamic membership group using New-MgGroup?
    Yes, you can create a dynamic membership group by specifying a membership rule during the group's creation. Here's an example:
    $groupParams = @{
        DisplayName = "Dynamic Group"
        MailNickname = "dynamicgroup"
        GroupTypes = @("Unified", "DynamicMembership")
        MailEnabled = $true
        SecurityEnabled = $false
        MembershipRule = '(user.department -eq "Sales")'
        MembershipRuleProcessingState = "On"
    }
    New-MgGroup -BodyParameter $groupParams
  • What are the differences between security groups and Microsoft 365 groups created with New-MgGroup?
    When creating groups with New-MgGroup, setting the GroupTypes parameter to @("Unified") creates a Microsoft 365 group, which includes collaboration features like shared mailboxes and SharePoint sites. Omitting the GroupTypes parameter or setting it to an empty array creates a security group, primarily used for assigning permissions to resources.
💡 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.
⚠️ You Must Provide Both mailNickname and displayName

When creating a new group using New-MgGroup, both displayName and mailNickname are required.

If either of these properties is missing, the command will fail with a 400 Bad Request error.
💡 Control Group Behavior with mailEnabled and securityEnabled

The behavior and purpose of the group depends on how you set these two properties:
  • mailEnabled = $true and securityEnabled = $false → Microsoft 365 Group
  • mailEnabled = $false and securityEnabled = $true → Security Group
  • mailEnabled = $true and securityEnabled = $true → Mail Enabled Security Group
Set these values correctly to ensure you're provisioning the intended group type.
🔐 Security vs. Microsoft 365 Groups – Know the Difference

While both can be created using New-MgGroup, only Microsoft 365 Groups (with groupTypes set to "Unified") come with collaboration features like a shared mailbox, calendar, Planner, and Teams integration.

In contrast, Security Groups are primarily used for access management and permissions control within Azure AD and Microsoft 365 services.

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