GitHub Icon Image
GitHub

Update Global Microsoft 365 Group Settings

Summary

Managing Microsoft 365 Group settings is crucial for maintaining a compliant and secure environment.PowerShell and Microsoft Graph can be used to configure various group settings, including naming policies, guest access, and more.

As a regular user of PnP PowerShell, I wanted to replicate the Microsoft Entra cmdlets for configuring group settings using PnP PowerShell.

Prerequisites

  • PnP PowerShell https://pnp.github.io/powershell/
  • The user account that runs the script must have Global Admin administrator access or Entra ID Admin role.
  • PnP PowerShell
param (
    [Parameter(Mandatory = $true)]
    [string] $domain
)
Clear-Host

$adminSiteURL = "https://$domain-Admin.SharePoint.com"
Connect-PnPOnline -Url $adminSiteURL

$BlockedWords = @("law","pension","finance","sea","ocean","river","lake","stream","creek","pond","pool","reservoir","dam","canal","ditch","drain","gutter","sewer","pipe","tube","hose","conduit","channel","aqua")

$unifiedSet = Get-PnPMicrosoft365GroupSettings -GroupSetting "Group.Unified"

$url = "/groupSettings/$($unifiedSet.Id)"
  
$Payload = @"
{
    "values": [
        {
            "name": "CustomBlockedWordsList",
            "value": "$($BlockedWords -join ',')"
        },
        {
            "name": "PrefixSuffixNamingRequirement",
            "value": "Test_[Department][GroupName][Office]"
        }
        ,
        {
            "name": "AllowToAddGuests",
            "value": "True"
        },
        {
            "name": "AllowGuestsToBeGroupOwner",
            "value": "False"
        },
        {
            "name": "AllowGuestsToAccessGroups",
            "value": "True"
        },
        {
            "name": "AllowToAddGuests",
            "value": "True"
        },
        {
            "name": "EnableGroupCreation",
            "value": "True"
        },
        {
            "name": "NewUnifiedGroupWritebackDefault",
            "value": "True"
        },
        {
            "name": "EnableMIPLabels",
            "value": "True"
        },
        {
            "name": "EnableMSStandardBlockedWords",
            "value": "False"
        }
     ]
}
"@


Invoke-PnPGraphMethod -Url $url -Method Patch -Content $Payload
(Get-PnPMicrosoft365GroupSettings -GroupSetting "Group.Unified").Values 

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell

The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?

Source Credit

Sample first appeared on Managing Microsoft 365 Group Settings with PnP PowerShell and Microsoft Graph

Contributors

Author(s)
Reshmee Auckloo

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI