Set a Microsoft 365 Group Naming Policy in Graph PowerShell Without Overwriting Other Group Settings
Add group name prefixes, suffixes and blocked words in Microsoft 365 with Graph PowerShell, keeping group creation and guest settings intact, with checks and rollback.

In this guide
Table of Contents
Table of contents
A Microsoft 365The KBY LexiconMicrosoft 365Microsoft 365 is Microsoft's subscription suite of Office apps and cloud services such as Exchange Online, SharePoint, OneDrive and Teams, run on an Entra ID tenant.
group naming policy is two values in the tenant’s Group.Unified directory setting: PrefixSuffixNamingRequirement and CustomBlockedWordsList. The same settings object also holds group creation restrictions, guest access and sensitivity label settings. Set the policy in the Microsoft Entra admin center (Microsoft Entra ID, then All groups > Groups > Naming policy) or with Update-MgBetaDirectorySetting. If you script it, read the whole Values collection first, save a copy, change only the two naming values and send every value back. Microsoft’s update reference says you must supply the entire collection, and its group settings guide warns that skipping the read can overwrite settings other than the one you meant to change. You need a Microsoft Entra IDThe KBY LexiconMicrosoft Entra IDA concise technical definition of Microsoft Entra ID: what it is, how it fits identity architecture, and where engineers must validate before change.
P1 (or Entra Basic EDU) licence, owned but not necessarily assigned, for each unique user who is a member of a Microsoft 365 group. Global Administrators and User Administrators are exempt from the policy, so test it with an ordinary account.
#The problem with changing one value at a time
Users create Microsoft 365 groups from Teams, Outlook, SharePoint and Planner, and without a convention the address list fills with names nobody can place. A naming policy adds fixed prefixes and suffixes, or values from the creator’s directory profile such as [Department], and rejects names that contain words you have blocked. It applies to the group name and alias in every workload that creates or edits groups. If you also have an existing Exchange group naming policy, the Microsoft Entra policy is the one enforced. It does not cover distribution groups created in Exchange OnlineThe KBY LexiconExchange OnlineExchange Online is Microsoft's cloud-hosted email, calendar and contacts service, delivered through Microsoft 365 as hosted mailbox infrastructure.
, which have their own naming policy.
Existing groups are not renamed when you save the policy. Microsoft’s Entra page says the policy is enforced the next time an owner edits the group name, even if they make no change; the Microsoft 365 page adds edits to the alias, description or avatar. Expect owners of older teams to see a prefix appear the first time they touch the group’s settings.
The risk in this change is not the policy itself but the object it lives in. If your tenant already has group creation restricted to an approved security group, that restriction is EnableGroupCreation and GroupCreationAllowedGroupId in the same Group.Unified object. Microsoft’s naming policy page shows an update that sends only the two naming values. The directory setting update reference, in its request body table, says: “You must supply the entire collection set. You cannot update a single set of values.” The pages disagree, so send the full collection: it satisfies both, and a naming change can’t then touch your creation restriction or guest settings.
#Moving parts in the Group.Unified setting
Tenant-wide Microsoft 365 group settings use a settings template and a settings object. The template named Group.Unified (ID 62375ab9-6b52-47ed-826b-58e47e0e304b) defines the available settings and their defaults. Until someone changes a default, the tenant has no settings object at all; the first change creates one from the template, and that object has its own ID. A template called Group.Unified.Guest holds per-group guest settings and is not involved here.
When the object exists, $Setting.Values returns name and value pairs including EnableGroupCreation, GroupCreationAllowedGroupId, AllowToAddGuests, AllowGuestsToAccessGroups, AllowGuestsToBeGroupOwner, EnableMIPLabels, UsageGuidelinesUrl, ClassificationList, NewUnifiedGroupWritebackDefault, PrefixSuffixNamingRequirement and CustomBlockedWordsList. Booleans appear as True and False. When you create the object through Microsoft Graph and specify only some values, the others take the template defaults.
#How the prefix and suffix are built
The format is Prefix[GroupName]Suffix. You can combine several fixed strings and attributes, but [GroupName] must appear exactly once. Supported attributes are [Department], [Company], [Office], [StateOrProvince], [CountryOrRegion] and [Title], taken from the user creating the group. Anything else in brackets, such as [postalCode], is treated as fixed text. Extension and custom attributes aren’t supported. With GRP_[GroupName]_[Department], a user in Engineering who types Bid Team gets a group called GRP_Bid Team_Engineering.
Characters that are valid in a group name but not in an alias stay in the name and are dropped from the alias, so the two can differ. A period or hyphen may appear anywhere except at the start or end of the name; an underscore may appear anywhere. If you use Viva Engage Office 365 connected groups, keep @, #, [, ], < and > out of the fixed text, or regular Viva Engage users can’t create groups. Pick attributes that every user has filled in, with short values.
Microsoft documents the length limit three ways:
| Microsoft page | What it limits | Limit |
|---|---|---|
| Microsoft 365 Groups and Teams naming policy | Total prefix and suffix string length when you create the policy | 53 characters |
| Enforce a naming policy in Microsoft Entra ID | Prefix and suffix strings including the group name | 63 characters |
| Configure group settings using PowerShell, and the Graph group settings overview | The PrefixSuffixNamingRequirement string | 64 characters |
Keeping the fixed text and attribute tokens under 53 characters satisfies all three. Short suffixes leave room for the name users actually type.

#How blocked words are matched
CustomBlockedWordsList is a comma-separated list of up to 5,000 phrases. Matching is case-insensitive and there are no character restrictions. There is no substring search: a group name must contain the blocked word exactly to fail, so blocking lass doesn’t stop a group called Class. When a user enters a blocked word, Teams, SharePoint and Outlook on the web show an error naming it. Outlook desktop, the Outlook mobile apps and the Microsoft 365 admin center don’t preview the enforced name but still apply the policy when the group is created or edited.
#Setting up the prefix, suffix and blocked words
Microsoft’s guide installs the Graph modules from an elevated Windows PowerShell session with Install-Module Microsoft.Graph -Scope AllUsers and Install-Module Microsoft.Graph.Beta -Scope AllUsers. The directory setting cmdlets used below are in the beta module. Run the rest from an ordinary session.
-
Connect and check the account. Microsoft’s guide uses this scope; confirm the account in the output before you go further.
1Connect-MgGraph -Scopes "Directory.ReadWrite.All" 2Get-MgContext -
Find out whether a
Group.Unifiedobject exists and save every value as your rollback record. If nothing is returned, the tenant is on defaults: do step 3, then use step 4 instead of step 5.1$Setting = Get-MgBetaDirectorySetting | Where-Object { $_.DisplayName -eq "Group.Unified" } 2$Setting.Id 3$Setting.Values | Select-Object Name, Value | 4 Export-Csv -Path .\group-unified-before.csv -NoTypeInformationOpen the CSV and check that it has a row for each setting and that values you know about, such as
EnableGroupCreation, are what you expect. Stop here if the file is empty while$Setting.Idhas a value. -
Check the attribute you plan to use. This lists users with no department.
1Get-MgUser -All -Property UserPrincipalName,Department | 2 Where-Object { -not $_.Department } | 3 Select-Object UserPrincipalNameMicrosoft advises using attributes that have a value for every user. Fill the gaps, or choose another attribute, before you go on.
-
If no settings object exists, create one from the template with only the naming values. The other settings take their defaults, which is what the tenant already uses.
1$Template = Get-MgBetaDirectorySettingTemplate | Where-Object { $_.DisplayName -eq "Group.Unified" } 2$params = @{ 3 templateId = $Template.Id 4 values = @( 5 @{ name = "PrefixSuffixNamingRequirement"; value = "GRP_[GroupName]_[Department]" } 6 @{ name = "CustomBlockedWordsList"; value = "Payroll,CEO,HR" } 7 ) 8} 9New-MgBetaDirectorySetting -BodyParameter $params -
If the object exists, build the full collection from what you just read, replacing only the two naming values, and send it all back.
1$merged = [ordered]@{} 2foreach ($v in $Setting.Values) { $merged[$v.Name] = [string]$v.Value } 3$merged["PrefixSuffixNamingRequirement"] = "GRP_[GroupName]_[Department]" 4$merged["CustomBlockedWordsList"] = "Payroll,CEO,HR" 5$values = foreach ($k in $merged.Keys) { @{ name = $k; value = $merged[$k] } } 6Update-MgBetaDirectorySetting -DirectorySettingId $Setting.Id -BodyParameter @{ values = @($values) }Every name the object already has is sent back with its current value, and the two naming values are added if they were missing.
To edit the blocked words later, start from the current list rather than retyping it. The portal’s Blocked words tab offers Download, and Microsoft notes that new entries must be added to the existing ones before you upload the file again.
#Check it worked from a non-exempt account
-
Read the object again and compare it with the rollback record. Only the two naming rows should differ.
1$After = Get-MgBetaDirectorySetting -DirectorySettingId $Setting.Id 2$After.Values | Select-Object Name, Value | 3 Export-Csv -Path .\group-unified-after.csv -NoTypeInformation 4Compare-Object (Import-Csv .\group-unified-before.csv) (Import-Csv .\group-unified-after.csv) -Property Name, ValueExpect at most four lines, marked
<=and=>: the old and newPrefixSuffixNamingRequirementand the old and newCustomBlockedWordsList. Any other name in the output means another setting changed; restore it from the CSV now. If you created a new object in step 4, there is no before file; check instead thatEnableGroupCreationreadsTrueandAllowToAddGuestsreadsTrue, the template defaults. -
Sign in to Teams or Outlook on the web as a user who holds neither Global Administrator nor User Administrator, start creating a group and type a name. The preview should show the prefix and the user’s department. Type
Payrollas the name and the client should refuse it with an error naming the word. Cancel without creating the group. -
In the Entra admin center, Naming policy should show the prefix and suffix you set and the blocked words list.

#What goes wrong after the policy is live
- An admin creates a group with no prefix and assumes the policy failed. Global Administrators and User Administrators are exempt across every workload, and the Microsoft 365 page also exempts Partner Tier 1 and Tier 2 Support. Test with an ordinary account.
- Some users’ groups come out without the department part you expected. Check the creator’s profile for an empty attribute; Microsoft advises using attributes that every user has filled in.
- A Classroom app or School Data Sync job starts failing. Those tools don’t apply the prefix and suffix for the user; the name supplied must already include them.
- Viva Engage users can no longer create groups. The fixed text includes one of
@ # [ ] < >. - An owner renames an old team and gets a different name from the one they typed. That is the policy applying on first edit, as documented. Warn owners before you switch it on.
- Guest or group creation behaviour changes after a naming update. Compare the object with your before CSV; if any value other than the two naming settings differs, restore it from the file.
#Permissions and the roles the policy ignores
Microsoft lists Global Administrator, Groups Administrator and Directory Writers as roles that can configure a naming policy; use Groups Administrator. The directory setting update reference names GroupSettings.ReadWrite.All as the least privileged Graph permission for the update itself, with Directory.ReadWrite.All as a higher privileged alternative. The guide’s Directory.ReadWrite.All scope covers the whole procedure, including the user read in step 3, but it is broad, so close the session when you finish. The exemption for Global Administrators and User Administrators means the policy is a convention for users, not a hard control: anyone in those roles can create a group called Payroll. Keep membership of those roles small and reviewed. A blocked words list is a naming rule, not a data protection control; it stops a team called HR, not HR data being shared somewhere else.
#Roll back to the saved settings
Every change above is reversible from the record you saved.
-
To restore the object exactly as it was, send the saved collection back.
1$Before = Import-Csv -Path .\group-unified-before.csv 2$values = foreach ($r in $Before) { @{ name = $r.Name; value = [string]$r.Value } } 3Update-MgBetaDirectorySetting -DirectorySettingId $Setting.Id -BodyParameter @{ values = @($values) }Then run the comparison from the validation section against the before file; it should return nothing.
-
If you created the object in step 4, remove the naming policy by setting both naming values to empty strings with the same read-modify-write loop. Leave the object in place: its other values are the defaults, so it behaves as the tenant did before.
-
In the portal, Delete policy on the Naming policy page removes all prefixes, suffixes and blocked words at once. Download the blocked words list first if you might want it back.
A rollback changes the policy, not group names. Groups named while it was on keep the name they were given unless their owners rename them.
#Checks to repeat after the change
Re-export Group.Unified to CSV after any change to group settings and compare it with the last known good copy; that one file covers creation, guest, label and naming settings together. A Microsoft 365 group expiration policy is a separate setting and needs its own check. Re-run the empty-attribute query after a bulk user import or an HR system change. Review the blocked words list when departments are renamed, since it matches whole words only. When the policy has been stable for a few weeks, decide whether older groups should be brought into line by asking owners to edit them, rather than renaming them centrally.
About this page
Credited to
Dates
Published
Sources
Corrections
No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.
Read-only scripts
- Windows devices with no BitLocker recovery key in Entra IDMicrosoft Entra ID, Windows
- Intune devices that haven't synced in N daysMicrosoft Intune
- Mailboxes forwarding to external addressesExchange Online
- BitLocker status of every volume on this PCWindows
Upcoming deadlines
- Intune moves to macOS 15 and laterQ4 2026
- SAP SuccessFactors provisioning: move from basic auth to workload identityNovember 2026
- Intune November release: JIT registration reminder at APNs renewal and automatic JIT for eligible tenantsNovember 2026
Explore KBY
The KBY Brief
A short email about twice a week with new runbooks, configuration traps and fixes from KBY Technologies.
SubscribeRelated Engineering Labs
Related articles
Enterprise IT Management
Restricting Microsoft 365 Group Creation to an Approved Security Group
How to limit Microsoft 365 Group creation to one approved security group with the Group.Unified directory setting, including state capture, validation from both sides, failure modes and a tested rollback.
Enterprise IT Management
Block Microsoft 365 Self-Service Purchases and Trials with the MSCommerce PowerShell Module
Block Microsoft 365 self-service purchases and trials product by product with MSCommerce, keep a CSV rollback record, verify the change and deal with existing subscriptions.
Enterprise IT Management
Scope Microsoft Graph Mail Access to Specific Mailboxes with Exchange Online RBAC for Applications
Scope an app's Graph mail access to specific mailboxes with RBAC for Applications in Exchange Online, test it, remove the unscoped Entra grant and keep a tested rollback.
Enterprise IT Management
Microsoft 365 Group Expiration Policy: Staged Rollout, Renewal and Restore
How to enable Microsoft 365 group expiration without a deletion wave: capture the policy, close ownership gaps, pilot on selected groups, widen to all, verify dates, and switch off and restore safely.
Discover more
Graduate Learning
Ops Playbook
- PlaybookMove Users From Microsoft 365 Apps for Business to Apps for Enterprise Without a License Gap
- PlaybookAuto-Remediating Stale Local Admin Group Membership Drift
- PlaybookKilling Expired Certificate Auth Failures with Auto-Renewal Hooks
- PlaybookAuto-Releasing Ghost-Booked Meeting Rooms Before Complaints Start
Lexicon Definitions
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Engineering insights, direct to you.
Receive the latest Systems Engineering tutorials, production guides, Engineering Labs and operational best practices.
Comments
Add a thoughtful note on Set a Microsoft 365 Group Naming Policy in Graph PowerShell Without Overwriting Other Group Settings. Comments are checked for spam and held for moderation before appearing.