Bulk Create Unified Groups Using PowerShell

Creating Microsoft 365 Unified Groups manually through the Entra admin center or Microsoft 365 admin portal can be slow when you have many teams, departments, or projects to onboard. A faster and cleaner approach is to bulk create Unified Groups using Microsoft Graph PowerShell, by importing group details from a CSV file and generating a report after execution.

In this M365Corner article, you’ll learn how to bulk create Unified Groups (Microsoft 365 Groups) using PowerShell, with built-in checks to avoid creating duplicates.

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

I) Script

Import-Module Microsoft.Graph.Groups
Connect-MgGraph -Scopes "Group.ReadWrite.All"
$CsvPath = ".\UnifiedGroups.csv"
$Groups  = Import-Csv $CsvPath

$Results = @()

foreach ($G in $Groups) {

    $DisplayName  = $G.DisplayName
    $MailNickname = $G.MailNickname
    $Description  = $G.Description

    Write-Host "Creating Unified Group: $DisplayName" -ForegroundColor Cyan

    try {

        # Optional: Check if group already exists with same MailNickname
        $Existing = Get-MgGroup -Filter "mailNickname eq '$MailNickname'" -ErrorAction SilentlyContinue

        if ($Existing) {
            Write-Host "Already exists, skipping: $DisplayName ($MailNickname)" -ForegroundColor Yellow

            $Results += [PSCustomObject]@{
                DisplayName  = $DisplayName
                MailNickname = $MailNickname
                Status       = "Skipped (Already Exists)"
                GroupId      = $Existing.Id
            }
            continue
        }

        $Params = @{
            DisplayName     = $DisplayName
            Description     = $Description
            MailEnabled     = $true
            MailNickname    = $MailNickname
            SecurityEnabled = $false
            GroupTypes      = @("Unified")
            Visibility      = "Private"
        }

        $NewGroup = New-MgGroup -BodyParameter $Params

        $Results += [PSCustomObject]@{
            DisplayName  = $DisplayName
            MailNickname = $MailNickname
            Status       = "Created"
            GroupId      = $NewGroup.Id
        }
    }
    catch {
        $Results += [PSCustomObject]@{
            DisplayName  = $DisplayName
            MailNickname = $MailNickname
            Status       = "Failed"
            GroupId      = ""
            Error        = $_.Exception.Message
        }

        Write-Host "Failed: $DisplayName -> $($_.Exception.Message)" -ForegroundColor Red
    }
}
$Results | Export-Csv ".\UnifiedGroupCreateResults.csv" -NoTypeInformation
Write-Host "`nDone! Results saved to UnifiedGroupCreateResults.csv" -ForegroundColor Green
                            

ii) How the Script Works

This script bulk creates Unified Groups (Microsoft 365 Groups) using Microsoft Graph PowerShell and a CSV input file.

  1. Imports the Microsoft Graph Groups module
  2. Import-Module Microsoft.Graph.Groups

    This module provides the group-related cmdlets required for the script such as:

    • Get-MgGroup
    • New-MgGroup
  3. Connects to Microsoft Graph with required permissions
  4. Connect-MgGraph -Scopes "Group.ReadWrite.All"

    The scope Group.ReadWrite.All is required because the script must:

    • check if a group exists
    • create new groups in Entra ID / Microsoft 365
  5. Imports the Unified Groups list from a CSV file
  6. $CsvPath = ".\UnifiedGroups.csv"
    $Groups  = Import-Csv $CsvPath
                                   

    Your CSV should contain these columns:

    DisplayName,MailNickname,Description
    Finance Team,FinanceTeam,Unified group for finance department collaboration
    HR Projects,HRProjects,HR planning and internal project discussions
    IT Support,ITSupport,IT team collaboration group
                                    
  7. Reads group values from each CSV row
  8. Inside the loop, the script assigns:
    $DisplayName = $G.DisplayName $MailNickname = $G.MailNickname
    $Description = $G.Description
    These values are used to create the group with consistent naming.

  9. Checks if the group already exists (duplicate protection)
  10. Before creating the group, the script checks if a group already exists with the same MailNickname:

    $Existing = Get-MgGroup -Filter "mailNickname eq '$MailNickname'" -ErrorAction SilentlyContinue

    If a match is found:

    • the group is skipped
    • the existing GroupId is recorded
    • the script moves to the next row

    This prevents accidental duplicates.

  11. Builds the group creation parameters
  12. The script creates a hashtable for the Unified Group configuration:

    $Params = @{
        DisplayName     = $DisplayName
        Description     = $Description
        MailEnabled     = $true
        MailNickname    = $MailNickname
        SecurityEnabled = $false
        GroupTypes      = @("Unified")
        Visibility      = "Private"
    }
                                    

    Key settings here:

    • MailEnabled = $true
      Required for Microsoft 365 Groups because they are mail-enabled.
    • SecurityEnabled = $false
      Ensures it is not created as a security group.
    • GroupTypes = @("Unified")
      This is the main property that makes it a Unified Group (Microsoft 365 Group).
    • Visibility = "Private"
      Creates the group as private (membership requires approval/invite).
  13. Creates the Unified Group
  14. The group is created using:

    $NewGroup = New-MgGroup -BodyParameter $Params

    If creation succeeds, the script logs:

    • Status = Created
    • GroupId = newly created group ID
  15. Captures errors cleanly
    If something fails, the script logs:
    • Status = Failed
    • Error message
    • GroupId blank

    This helps with troubleshooting and re-running only failed entries.

  16. Exports a results report
  17. At the end, the script exports a report:

    $Results | Export-Csv ".\UnifiedGroupCreateResults.csv" -NoTypeInformation

    This file becomes your audit log showing:

    • Created groups
    • Skipped groups
    • Failed groups with error messages

iii) Further Enhancements

Here are a few useful improvements you can add later (without changing your current script):

  1. Allow visibility selection from CSV
    Instead of always setting:
    Visibility = "Private"
    You can add a CSV column like:
    • Visibility (Public/Private)
  2. Automatically add owners and members after creation
  3. Unified groups are most useful when:

    • owners are assigned
    • members are added automatically

    You can extend the script to add:

    • Owners via New-MgGroupOwnerByRef
    • Members via New-MgGroupMemberByRef
  4. Enable Teams for created Unified Groups
  5. If the goal is to create Teams-ready groups, you can add an optional step to:

    • create a Team from the group
  6. Add retry logic for Graph throttling
  7. In large bulk operations, Graph may throttle requests. A retry mechanism can help avoid partial failures.

  8. Export more details into the report
  9. You can add fields like:

    • CreatedDateTime
    • Visibility
    • MailEnabled status
    • GroupType confirmation

Possible Errors & Solutions

Error Cause Solution
Insufficient privileges to complete the operation The signed-in user does not have permission to create Microsoft 365 groups.
  • Use an admin account such as Global Administrator or Groups Administrator
  • Ensure you connect with:
  • Connect-MgGraph -Scopes "Group.ReadWrite.All"
Another object with the same value for property mailNickname already exists A group already exists with the same MailNickname. This script already handles it using the existing group check and marks the entry as:
✅ Skipped (Already Exists)
Invalid value specified for property 'mailNickname' MailNickname contains invalid characters or spaces. Use a clean nickname format:
  • no spaces
  • avoid special characters
  • use letters/numbers only
    Example:
Request_ResourceNotFound / Request_BadRequest Commonly caused by invalid input values in the CSV or missing headers. Ensure your CSV includes:
  • DisplayName
  • MailNickname
  • Description
TooManyRequests / throttling Microsoft Graph throttling due to high request volume.
  • Split the CSV into smaller batches
  • Add retry logic as an enhancement

Conclusion

Bulk creating Unified Groups is a common Microsoft 365 onboarding task—especially when new departments, projects, or teams are introduced frequently.

This Microsoft Graph PowerShell script helps you:

✅ Create Unified Groups in bulk using a CSV file
✅ Avoid duplicates by checking existing MailNicknames
✅ Capture success/failure results cleanly
✅ Export a detailed report for auditing and tracking

Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                            


                            


                            

© Created and Maintained by LEARNIT WELL SOLUTIONS. All Rights Reserved.