Table of Contents
Block Guest Access to Teams with Group Settings
Updated 10-Oct-2023

By default, Microsoft 365 tenants can add guest users (people with accounts outside your tenant) to the membership of Microsoft 365 Groups (and Teams). In this article, we’ll explore how to block guests for individual groups and teams.
Tenants control guest access through the Azure Active Directory policy for Groups, which has two relevant settings:
- AllowToAddGuests: Controls if group (or team) owners can add guest users to membership. The default is True.
- AllowGuestsToAccessGroups: Controls if guest accounts can access resources through Office 365 Groups. The default is True.
Settings in the Entra ID directory policy for Microsoft 365 Groups can be changed through PowerShell. For instance, to block group owners from being able to add guests, you change the value of AllowToAddGuests to False. These command fetch the current settings, update the value, and update the policy (assuming that you have already created a tenant policy):
Connect-MgGraph -Scopes Group.Read.All, Directory.ReadWrite.All $TenantSettings = Get-MgBetaDirectorySetting | Where-Object {$_.DisplayName -eq "Group.Unified"} $Values = $TenantSettings.Values ($Values | Where-Object Name -eq 'AllowToAddGuests').Value = "false" Update-MgBetaDirectorySetting -DirectorySettingId $TenantSettings.Id -Values $Values
Guests who are members of groups can continue to use their membership. The block simply stops group owners adding new guests. See this article for more information about configuring and managing the settings of the Entra ID policy for Microsoft 365 groups.
Block Guest Access to Teams and Groups on an Individual Basis
The normal course of events is to allow guest users for groups and selectively block access for specific groups that hold confidential information. It’s relatively easy to find and block access to selected groups. In the following example, the code:
- Find the group policy template object for the tenant.
- Finds a set of Microsoft 365 groups whose classification is set to “Secret.” You could use whatever filter you like to find the set of target groups.
- Checks if an existing custom setting exists for a group. If one isn’t present, the code applies a new setting to block guest access. If one is, the setting is updated to block guest access.
$GroupTemplate = (Get-MgBetaDirectorySettingTemplate | Where-Object {$_.DisplayName -eq "Group.Unified.Guest"}) [array]$Groups = (Get-UnifiedGroup -ResultSize Unlimited | Where-Object {$_.Classification -eq "Secret"}) ForEach ($Group in $Groups) { $GroupSettings = Get-MgGroupSetting -GroupId $Group.ExternalDirectoryObjectId If ($GroupSettings) { # Policy settings already exist for the group - so update them $GroupSettings = Get-MgGroupSetting -GroupId $Group.ExternalDirectoryObjectId Update-MgGroupSetting -GroupId $Group.ExternalDirectoryObjectId -TemplateId $GroupTemplateId ` -GroupSettingId $GroupSettings.Id -Values (@{'name'='AllowToAddGuests';'value'='false'}) | ConvertTo-Json Write-Host ("External Guest accounts blocked for {0}" -f $Group.DisplayName) } Else { # Settings do not exist for the group - so create a new settings object and update $Status = New-MgGroupSetting -GroupId $Group.ExternalDirectoryObjectId -TemplateId $GroupTemplateId ` -Values (@{'name'='AllowToAddGuests';'value'='false'}) | ConvertTo-Json Write-Host ("New settings created and guests blocked for {0}" -f $Group.DisplayName) } }
The process of updating the directory setting to block guests in teams and groups happens when you apply a sensitivity label that blocks guests in teams and group.
Block Guest Access to Teams Individually Trumps Tenant Setting
Some people would like to reverse the process and block guest access to all groups except on a selective basis. This isn’t possible because the tenant-level block trumps settings at an individual group level. Once you set AllowToAddGuests to False at the tenant level, the policy stops any group owner from adding guests to group membership. Only administrators keep the ability to add guests, and they can only do so through an admin interface like running the Add-UnifiedGroupLinks cmdlet or updating group membership in the Microsoft 365 Admin Center or Entra ID admin center.
If you want to block access for guests to all but a small set of groups, you must leave AllowToAddGuests as True at the tenant level and then block all but the set of groups you want to allow guests to join.
Block Guest Access to Teams Through Sensitivity Labels
Generally available from June 2020, if you enable sensitivity labels for use with Groups, Teams, and Sites, the container settings in the labels can be used to block guest users. For example, you can have a label called Confidential which, when applied to a group, stops new guests being added. Existing guests aren’t removed, but you can find them as described here.
This is the kind of topic we cover in Managing Groups chapter of the Office 365 for IT Pros eBook. You can find a lot more about managing Groups there.
This should actually be tagged as Chapter 10. I started to reread through 12, and it directs you to Chapter 10 which is where I found what I needed.
The tag relates to a previous version of the book. It’s kind of hard to keep old posts updated when so much is changing…
Post is now updated. You should read up on sensitivity labels as they make the process of managing guest access to individual groups much easier.