m365Corner
M365 Blogs

Ultimate Guide for Using New-MgGroup Cmdlet

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.

What Are Microsoft 365 Groups?

Microsoft 365 Groups are a cross-application membership service. They bring together people, information, and resources, providing access to shared tools like:

  • Outlook: For shared mailboxes and calendars.
  • Teams: For real-time communication and collaboration.
  • SharePoint: For document management and sharing.
  • Planner: For task management.

A Microsoft 365 Group automatically provisions these resources, making it easier for teams to collaborate without the need for additional setup.

Why Use New-MgGroup?

The New-MgGroup cmdlet allows administrators to:

  • Automate group creation processes for consistency and efficiency.
  • Create multiple groups in bulk, saving time.
  • Assign specific attributes, such as mail nicknames and security settings, during group creation.

By using New-MgGroup, you can streamline workflows and reduce the chances of errors associated with manual group creation.

Setting Up Microsoft Graph PowerShell

To use New-MgGroup, you’ll need to install and configure the Microsoft Graph PowerShell module:

  1. Install Microsoft Graph PowerShell: Install the module with the following command:
    Install-Module Microsoft.Graph -Scope CurrentUser
  2. Connect to Microsoft Graph: Connect to your Microsoft 365 tenant with the required permissions:
    Connect-MgGraph -Scopes "Group.ReadWrite.All"
  3. You will be prompted to log in with your admin credentials.

  4. Disconnect After Use: Disconnect your session when tasks are complete:
    Disconnect-MgGraph

Practical Examples of New-MgGroup

Create a Single Group

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.

Create Multiple Groups

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.

Create Multiple Groups from a CSV File

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.

Key Parameters & Configuration Options (Quick Reference)

Understanding key properties helps you create Teams more effectively.

Parameter Required Purpose
DisplayName Yes Name of the Group
MailNickname Yes Email alias
MailEnabled/td> Yes Enables email functionality
SecurityEnabled Yes Determines security group behavior
GroupTypes Optional Defines type (Unified, DynamicMembership)/td>
Description Optional Group purpose
MembershipRule Optional Required for dynamic groups
Visibility Optional Public or Private group
💡 The combination of MailEnabled, SecurityEnabled, and GroupTypes determines the type of group being created.

When Should You Use New-MgGroup?

Use the New-MgGroup cmdlet in the following scenarios:

  • Bulk group provisioning for departments, roles, or projects
  • Automating group creation workflows during onboarding
  • Creating dynamic groups based on user attributes
  • Standardizing naming conventions and configurations
💡 PowerShell-based automation ensures consistency and scalability, especially in large environments.

New-MgGroup vs Admin Center

Method Best For Limitation
New-MgGroup (PowerShell) Bulk creation, automation Requires scripting knowledge
Microsoft 365 Admin Center Manual group creation Not scalable
Entra Admin Center/td> Advanced management Limited automation
💡 For enterprise environments, New-MgGroup is the preferred approach due to automation capabilities.

Real-World Automation Scenarios

  1. Department-Based Group Creation
    • Automatically create groups for HR, Finance, IT
    • Apply consistent naming conventions
  2. Dynamic Group Provisioning
    • Create groups based on rules (e.g., department, domain)
    • Automatically update membership using MembershipRule
  3. Bulk Group Creation via CSV
    • Import group data and create multiple groups at once
    • Ideal for large-scale deployments
  4. Application & Access Control Groups
    • Create security groups for resource access
    • Use groups for role-based access control
💡 New-MgGroup is widely used for both collaboration (M365 groups) and access management (security groups).

Common Limitations & Considerations

Strengths

  • Supports bulk and automated group creation
  • Enables dynamic group membership
  • Integrates with Microsoft Graph ecosystem

Limitations

  • Requires correct permissions (Group.ReadWrite.All)
  • Cannot create distribution lists via Graph PowerShell
  • Owners/members often require separate cmdlets

Pro Tips for Using New-MgGroup

  • Always define group type clearly (Unified vs Security)
  • Use -BodyParameter for advanced configurations
  • Validate mail nickname uniqueness
  • Use dynamic rules carefully to avoid unintended memberships
  • Combine with lifecycle scripts for full automation
💡 These practices improve reliability and reduce administrative overhead.

Example: End-to-End Group Provisioning Workflow

A practical workflow could look like:

  1. Create group using New-MgGroup
  2. Add owners using New-MgGroupOwnerByRef
  3. Add members using New-MgGroupMember
  4. Assign licenses (if applicable)
  5. Integrate with Teams or SharePoint
💡 Microsoft 365 Groups act as the foundation for Teams, SharePoint, and Planner, making them critical for collaboration.

Frequently Asked Questions

  • What is New-MgGroup used for?
  • New-MgGroup is used to create Microsoft 365 groups using Graph PowerShell, enabling automation and bulk provisioning.

  • What types of groups can I create with New-MgGroup?
  • You can create Microsoft 365 (Unified) groups and security groups, including dynamic groups.

  • What permissions are required?
  • You need permissions such as Group.ReadWrite.All to create groups successfully.

  • Can I create multiple groups using New-MgGroup?
  • Yes, you can import data from a CSV file and create multiple groups in bulk.

  • Can I create distribution lists using New-MgGroup?
  • No, distribution lists are not supported via Graph PowerShell and require other tools

Advanced Tips for New-MgGroup Usage

  • Set Additional Properties During Creation: Specify visibility and description:
  • New-MgGroup -DisplayName "Dev Team" -MailNickname "devteam" -MailEnabled:$true -GroupTypes @("Unified") -Visibility "Private" -Description "Development team working on internal projects"
  • Automate Workflows: Combine with New-MgGroupMember to streamline processes:
  • $groupId = (New-MgGroup -DisplayName "Support Team" -MailNickname "supportteam" -MailEnabled:$true -GroupTypes @("Unified") -SecurityEnabled:$false).Id
    New-MgGroupMember -GroupId $groupId -DirectoryObjectId "user-id"
                            
  • Simulate Commands: Use the -WhatIf parameter to preview the outcome:
  • New-MgGroup -DisplayName "Test Group" -MailNickname "testgroup" -MailEnabled:$true -GroupTypes @("Unified") -SecurityEnabled:$false -WhatIf

Conclusion

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!

🚀 Community Edition Released!

Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.

Get it on GitHub Know More