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.

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!

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.