Skip to content
EliteGo IT

Projects & Field Notes

  • Microsoft 365
  • Security

Bringing Teams sprawl under control by restricting who can create groups

A business client's staff could create teams freely, and duplicate, ownerless teams and SharePoint sites were piling up. They wanted creation limited to approved people.

Client
Business client (name withheld)

The problem

Every user in the client’s Microsoft 365 tenant could create a Microsoft 365 Group, which also creates a team, a SharePoint site, a shared mailbox and a Planner plan. Over time this produced duplicate teams, sites nobody owned and files scattered across them. The client wanted only team leads and IT to be able to create new groups.

What we found

  • Group creation was open to every user, which is the Microsoft 365 default
  • Several teams covered the same purpose, and some had no active owner
  • There was no request route, so people created a new team whenever they needed one
  • The licensing included Microsoft Entra ID P1, which this control requires for the admin and for the allowed group’s members
Microsoft Teams showing a restricted user that they do not have permission to create a team
What a restricted user sees when trying to create a team

What we did

  1. Created a security group for the people allowed to create groups, with approved staff added as members.
  2. Applied the restriction through the tenant’s Group.Unified directory setting with Microsoft Graph PowerShell. The script keeps every other value already in that setting (such as naming or guest settings) and changes only the two values involved, so it’s safe to run again.
  3. Waited for the change to apply, then tested with a restricted user (blocked) and an allowed user (able to create a team).
  4. Agreed a simple request route with the client, so staff know who to ask for a new team.
Security group in Microsoft 365 whose members are allowed to create groups and teams
The security group that controls who can create groups
<#
.SYNOPSIS
    Restricts Microsoft 365 Group (and Teams) creation to members of one security group.
.PREREQUISITES
    Install-Module Microsoft.Graph.Groups, Microsoft.Graph.Beta.Identity.DirectoryManagement -Scope CurrentUser
    An account with Global Administrator or Groups Administrator (consents Directory.ReadWrite.All).
.EXAMPLE
    .\Set-GroupCreators.ps1 -AllowedGroupName 'M365 Group Creators' -Verbose
.ROLLBACK
    .\Set-GroupCreators.ps1 -AllowedGroupName 'M365 Group Creators' -AllowGroupCreation $true
#>
[CmdletBinding()]
param(
    [Parameter(Mandatory)][string]$AllowedGroupName,
    [bool]$AllowGroupCreation = $false   # $false = only the allowed group (and admins) can create groups
)

$ErrorActionPreference = 'Stop'
$templateId = '62375ab9-6b52-47ed-826b-58e47e0e304b'   # Group.Unified settings template (fixed, same in every tenant)

try {
    Import-Module Microsoft.Graph.Groups, Microsoft.Graph.Beta.Identity.DirectoryManagement
    Connect-MgGraph -Scopes 'Directory.ReadWrite.All', 'Group.Read.All' -NoWelcome

    # Find exactly one group with that name (escape single quotes for the OData filter)
    $safeName = $AllowedGroupName -replace "'", "''"
    $group = @(Get-MgGroup -Filter "displayName eq '$safeName'" -All)
    if ($group.Count -ne 1) { throw "Expected one group named '$AllowedGroupName', found $($group.Count)." }
    Write-Verbose "Allowed group: $($group[0].DisplayName) ($($group[0].Id))"

    # Get the tenant's Group.Unified setting, or create it from the template if it doesn't exist yet
    $setting = Get-MgBetaDirectorySetting -All | Where-Object TemplateId -eq $templateId
    if (-not $setting) {
        Write-Verbose 'No Group.Unified setting found. Creating it from the template.'
        $setting = New-MgBetaDirectorySetting -BodyParameter @{
            templateId = $templateId
            values     = @(@{ name = 'EnableGroupCreation'; value = 'true' })
        }
        $setting = Get-MgBetaDirectorySetting -DirectorySettingId $setting.Id
    }

    # Keep every existing value, change only the two we care about
    $values = [ordered]@{}
    foreach ($v in $setting.Values) { $values[$v.Name] = $v.Value }
    $values['EnableGroupCreation']         = $AllowGroupCreation.ToString().ToLower()
    $values['GroupCreationAllowedGroupId'] = $group[0].Id

    $body = @{ values = @($values.GetEnumerator() | ForEach-Object { @{ name = $_.Key; value = [string]$_.Value } }) }
    Update-MgBetaDirectorySetting -DirectorySettingId $setting.Id -BodyParameter $body

    # Show the result
    (Get-MgBetaDirectorySetting -DirectorySettingId $setting.Id).Values |
        Where-Object Name -in 'EnableGroupCreation', 'GroupCreationAllowedGroupId' |
        Format-Table Name, Value -AutoSize
}
catch {
    Write-Error "Group creation setting not applied: $($_.Exception.Message)"
    throw
}
finally {
    Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
}

To change the allowed group later, the script is run again with the new name. Running it with -AllowGroupCreation $true removes the restriction.

The result

Only approved staff and administrators can now create Microsoft 365 Groups and teams. Everyone else sees a message asking them to contact their administrator, and new teams go through one agreed route. The setting is documented and can be changed or rolled back with one command.

What to take from it

Restricting group creation is quick, but put a request route in place first, or people fall back to email and personal file shares. Check licensing before switching it on, and pair it with a group expiration policy so unused teams are reviewed rather than left behind.