用于配置组设置的 Microsoft Entra cmdlet

本文包含有关在属于 Microsoft Entra 的 Microsoft Entra ID 中使用 PowerShell cmdlet 创建和更新组的说明。 此内容仅适用于 Microsoft 365 组(有时称为统一组)。

重要

某些设置需要 Microsoft Entra ID P1 许可证。 有关详细信息,请参阅模板设置表。

若要详细了解如何防止非管理员用户创建安全组,请按照 Update-MgPolicyAuthorizationPolicy 中所述将 AllowedToCreateSecurityGroups 属性设置为 False。

Microsoft 365 组设置使用 Settings 对象和 SettingsTemplate 对象配置。 起初,目录中不会显示任何设置对象,因为目录配置为默认设置。 若要更改默认设置,必须使用设置模板创建新的设置对象。 设置模板由 Microsoft 定义。 有几个不同的设置模板。 若要配置目录的 Microsoft 365 组设置,请使用名为“Group.Unified”的模板。 若要针对单个组配置 Microsoft 365 组设置,请使用名为“Group.Unified.Guest”的模板。 此模板用于管理对 Microsoft 365 组的来宾访问权限。

这些 cmdlet 是 Microsoft Graph PowerShell 模块的一部分。 有关如何在计算机上下载和安装该模块的说明,请参阅安装 Microsoft Graph PowerShell SDK

重要

我们计划在 2024 年 3 月 30 日弃用 Azure AD PowerShell。 若要了解详细信息,请阅读有关弃用的更新。 我们建议迁移到 Microsoft Graph PowerShell,以便与 Microsoft Entra ID(以前称为 Azure AD)进行交互。 Microsoft Graph PowerShell 在 PowerShell 7 上提供,支持访问所有 Microsoft Graph API。 有关常见迁移查询的解答,请参阅迁移常见问题解答

注意

即使适当设置限制将来宾添加到 Microsoft 365 组,管理员仍可将来宾用户添加到 Microsoft 365 组。 此设置将限制非管理员用户将来宾用户添加到 Microsoft 365 组。

安装 PowerShell cmdlet

按照安装 Microsoft Graph PowerShell SDK 中所述安装 Microsoft Graph cmdlet。

  1. 以管理员身份打开 Windows PowerShell 应用。

  2. 安装 Microsoft Graph cmdlet。

    Install-Module Microsoft.Graph -Scope AllUsers
    
  3. 安装 Microsoft Graph beta cmdlet。

    Install-Module Microsoft.Graph.Beta -Scope AllUsers
    

在目录级别创建设置

这些步骤在目录级别创建设置,这些设置适用于目录中的所有 Microsoft 365 组。

  1. 在 DirectorySettings cmdlet 中,必须指定要使用的 SettingsTemplate 的 ID。 如果你不知道此 ID,此 cmdlet 将返回所有设置模板的列表:

    Get-MgBetaDirectorySettingTemplate
    

    此 cmdlet 调用返回可用的所有模板:

    Id                                   DisplayName         Description
    --                                   -----------         -----------
    62375ab9-6b52-47ed-826b-58e47e0e304b Group.Unified       ...
    08d542b9-071f-4e16-94b0-74abb372e3d9 Group.Unified.Guest Settings for a specific Microsoft 365 group
    16933506-8a8d-4f0d-ad58-e1db05a5b929 Company.BuiltIn     Setting templates define the different settings that can be used for the associ...
    4bc7f740-180e-4586-adb6-38b2e9024e6b Application...
    898f1161-d651-43d1-805c-3b0b388a9fc2 Custom Policy       Settings ...
    5cf42378-d67d-4f36-ba46-e8b86229381d Password Rule       Settings ...
    
  2. 若要添加使用准则 URL,首先需获取定义使用准则 URL 值的 SettingsTemplate 对象,即 Group.Unified 模板:

    $TemplateId = (Get-MgBetaDirectorySettingTemplate | where { $_.DisplayName -eq "Group.Unified" }).Id
    $Template = Get-MgBetaDirectorySettingTemplate | where -Property Id -Value $TemplateId -EQ
    
  3. 创建一个对象,其中包含要用于目录设置的值。 这些值更改了使用准则值,并启用了敏感度标签。 根据需要在模板中设置这些设置或任何其他设置:

    $params = @{
       templateId = "$TemplateId"
       values = @(
          @{
             name = "UsageGuidelinesUrl"
             value = "https://guideline.example.com"
          }
          @{
             name = "EnableMIPLabels"
             value = "True"
          }
       )
    }
    
  4. 使用 New-MgBetaDirectorySetting 创建目录设置:

    New-MgBetaDirectorySetting -BodyParameter $params
    
  5. 可使用以下命令读取值:

    $Setting = Get-MgBetaDirectorySetting | where { $_.DisplayName -eq "Group.Unified"}
    $Setting.Values
    

在目录级别更新设置

若要在设置模板中更新 UsageGuideLinesUrl 的值,请从 Microsoft Entra ID 读取当前设置,否则我们可能最终会覆盖 UsageGuideLinesUrl 以外的现有设置。

  1. 从 Group.Unified SettingsTemplate 获取当前设置:

    $Setting = Get-MgBetaDirectorySetting | where { $_.DisplayName -eq "Group.Unified"}
    
  2. 检查当前设置:

    $Setting.Values
    

    此命令返回以下值:

    Name                            Value
    ----                            -----
    EnableMIPLabels                 True
    CustomBlockedWordsList
    EnableMSStandardBlockedWords    False
    ClassificationDescriptions
    DefaultClassification
    PrefixSuffixNamingRequirement
    AllowGuestsToBeGroupOwner       False
    AllowGuestsToAccessGroups       True
    GuestUsageGuidelinesUrl
    GroupCreationAllowedGroupId
    AllowToAddGuests                True
    UsageGuidelinesUrl              https://guideline.example.com
    ClassificationList
    EnableGroupCreation             True
    NewUnifiedGroupWritebackDefault True
    
  3. 若要删除 UsageGuideLinesUrl 的值,请将 URL 编辑为空字符串:

    $params = @{
       Values = @(
          @{
             Name = "UsageGuidelinesUrl"
             Value = ""
          }
       )
    }
    
  4. 使用 Update-MgBetaDirectorySetting cmdlet 来更新值:

    Update-MgBetaDirectorySetting -DirectorySettingId $Setting.Id -BodyParameter $params
    

模板设置

以下是 Group.Unified SettingsTemplate 中定义的设置。 除非另有说明,否则这些功能需要 Microsoft Entra ID P1 许可证。

设置 说明
  • EnableGroupCreation
  • 键入:布尔
  • 默认值:True
一个标志,指明是否允许非管理员用户在目录中创建 Microsoft 365 组。 此设置不需要 Microsoft Entra ID P1 许可证。
  • GroupCreationAllowedGroupId
  • 键入:String
  • 默认值:""
安全组的 GUID,允许该组的成员创建 Microsoft 365 组,即使 EnableGroupCreation == false。
  • UsageGuidelinesUrl
  • 键入:String
  • 默认值:""
组使用准则链接。
  • ClassificationDescriptions
  • 键入:String
  • 默认值:""
以逗号分隔的分类说明列表。 ClassificationDescriptions 的值仅以此格式有效:
$setting["ClassificationDescriptions"] ="Classification:Description,Classification:Description"
其中,Classification 与 ClassificationList 中的条目匹配。
当 EnableMIPLabels == True 时,此设置不适用。
属性 ClassificationDescriptions 的字符限制为 300,不能对逗号进行转义。
  • DefaultClassification
  • 键入:String
  • 默认值:""
如果未指定,则为要用作组的默认分类的分类。
当 EnableMIPLabels == True 时,此设置不适用。
  • PrefixSuffixNamingRequirement
  • 键入:String
  • 默认值:""
最大长度为 64 个字符的字符串,用于定义为 Microsoft 365 组配置的命名约定。 有关详细信息,请参阅对 Microsoft 365 组强制实施命名策略
  • CustomBlockedWordsList
  • 键入:String
  • 默认值:""
逗号分隔字符串,用于列出不允许用户在组名称或别名中使用的短语。 有关详细信息,请参阅对 Microsoft 365 组强制实施命名策略
  • EnableMSStandardBlockedWords
  • 键入:布尔
  • 默认值:“False”
已否决。 请勿使用。
  • AllowGuestsToBeGroupOwner
  • 键入:布尔
  • 默认值:False
一个布尔值,该值指示来宾用户是否可以作为组的所有者。
  • AllowGuestsToAccessGroups
  • 键入:布尔
  • 默认值:True
一个布尔值,指示来宾用户是否可以访问 Microsoft 365 组的内容。 此设置不需要 Microsoft Entra ID P1 许可证。
  • GuestUsageGuidelinesUrl
  • 键入:String
  • 默认值:""
指向来宾使用指南的链接的 URL。
  • AllowToAddGuests
  • 键入:布尔
  • 默认值:True
一个布尔值,该值指示是否允许将来宾添加到此目录。
如果 EnableMIPLabels 设置为 True 且某个来宾策略与分配给组的敏感性标签相关联,则此设置可能会被重写,变成只读。
如果在组织级别将 AllowToAddGuests 设置设为 False,则会忽略组级别的任何 AllowToAddGuests 设置。 如果希望仅对几个组启用来宾访问,则必须在组织级别将 AllowToAddGuests 设为 true,然后针对特定组有选择地禁用它。
  • ClassificationList
  • 键入:String
  • 默认值:""
一个逗号分隔列表,用于列出可以应用于 Microsoft 365 组的有效分类值。
当 EnableMIPLabels == True 时,此设置不适用。
  • EnableMIPLabels
  • 键入:布尔
  • 默认值:“False”
一个标记,表明在 Microsoft Purview 合规门户发布的敏感性标签是否适用于 Microsoft 365 组。 有关详细信息,请参阅为 Microsoft 365 组分配敏感度标签
  • NewUnifiedGroupWritebackDefault
  • 键入:布尔
  • 默认值:“True”
使管理员可以新建 Microsoft 365 组而无需在请求负载中设置 groupWritebackConfiguration 资源类型的标志。 在 Microsoft Entra Connect 中配置组写回时,此设置适用。 “NewUnifiedGroupWritebackDefault”是全局 Microsoft 365 组设置。 默认值为 true。 将此设置值更新为 false 时,将会更改新建的 Microsoft 365 组的默认写回行为,而不会更改现有 Microsoft 365 组的 isEnabled 属性值。 组管理员需要显式更新组 isEnabled 属性值,才能更改现有 Microsoft 365 组的写回状态。

示例:在目录级别为组配置来宾策略

  1. 获取所有设置模板:

    Get-MgBetaDirectorySettingTemplate
    
  2. 若要在目录级别为组设置来宾策略,需要 Group.Unified 模板。

    $Template = Get-MgBetaDirectorySettingTemplate | where -Property Id -Value "62375ab9-6b52-47ed-826b-58e47e0e304b" -EQ
    
  3. 为指定的模板设置 AllowToAddGuests 的值:

    $params = @{
       templateId = "62375ab9-6b52-47ed-826b-58e47e0e304b"
       values = @(
          @{
             name = "AllowToAddGuests"
             value = "False"
          }
       )
    }
    
  4. 接下来,使用 New-MgBetaDirectorySetting cmdlet 创建新的设置对象:

    $Setting = New-MgBetaDirectorySetting -BodyParameter $params
    
  5. 可以使用以下命令读取值:

    $Setting.Values
    

在目录级别读取设置

如果知道要检索的设置的名称,可以使用以下 cmdlet 检索当前的设置值。 在此示例中,我们要检索名为“UsageGuidelinesUrl”的设置的值。

(Get-MgBetaDirectorySetting).Values | where -Property Name -Value UsageGuidelinesUrl -EQ

这些步骤在目录级别读取设置,这些设置适用于目录中的所有 Office 组。

  1. 读取所有现有的目录设置:

    Get-MgBetaDirectorySetting -All
    

    此 cmdlet 返回所有目录设置的列表:

    Id                                   DisplayName   TemplateId                           Values
    --                                   -----------   ----------                           ------
    c391b57d-5783-4c53-9236-cefb5c6ef323 Group.Unified 62375ab9-6b52-47ed-826b-58e47e0e304b {class SettingValue {...
    
  2. 读取特定组的所有设置:

    Get-MgBetaGroupSetting -GroupId "ab6a3887-776a-4db7-9da4-ea2b0d63c504"
    
  3. 使用设置 ID GUID 读取特定目录设置对象的所有目录设置值:

    (Get-MgBetaDirectorySetting -DirectorySettingId "c391b57d-5783-4c53-9236-cefb5c6ef323").values
    

    此 cmdlet 返回此特定组的此设置对象中的名称和值:

    Name                          Value
    ----                          -----
    ClassificationDescriptions
    DefaultClassification
    PrefixSuffixNamingRequirement
    CustomBlockedWordsList        
    AllowGuestsToBeGroupOwner     False 
    AllowGuestsToAccessGroups     True
    GuestUsageGuidelinesUrl
    GroupCreationAllowedGroupId
    AllowToAddGuests              True
    UsageGuidelinesUrl            https://guideline.example.com
    ClassificationList
    EnableGroupCreation           True
    

在目录级别删除设置

这些步骤在目录级别删除设置,这些设置适用于目录中的所有 Office 组。

Remove-MgBetaDirectorySetting -DirectorySettingId "c391b57d-5783-4c53-9236-cefb5c6ef323c"

创建特定组的设置

  1. 获取设置模板。

    Get-MgBetaDirectorySettingTemplate
    
  2. 在结果中,查找名为“Groups.Unified.Guest”的设置模板:

    Id                                   DisplayName            Description
    --                                   -----------            -----------
    62375ab9-6b52-47ed-826b-58e47e0e304b Group.Unified          ...
    08d542b9-071f-4e16-94b0-74abb372e3d9 Group.Unified.Guest    Settings for a specific Microsoft 365 group
    4bc7f740-180e-4586-adb6-38b2e9024e6b Application            ...
    898f1161-d651-43d1-805c-3b0b388a9fc2 Custom Policy Settings ...
    5cf42378-d67d-4f36-ba46-e8b86229381d Password Rule Settings ...
    
  3. 检索 Groups.Unified.Guest 模板的模板对象:

    $Template1 = Get-MgBetaDirectorySettingTemplate | where -Property Id -Value "08d542b9-071f-4e16-94b0-74abb372e3d9" -EQ
    
  4. 获取要对其应用此设置的组的 ID:

    $GroupId = (Get-MgGroup -Filter "DisplayName eq '<YourGroupName>'").Id
    
  5. 创建新设置:

    $params = @{
       templateId = "08d542b9-071f-4e16-94b0-74abb372e3d9"
       values = @(
          @{
             name = "AllowToAddGuests"
             value = "False"
          }
       )
    }
    
  6. 创建组设置:

    New-MgBetaGroupSetting -GroupId $GroupId -BodyParameter $params
    
  7. 若要验证设置,请运行以下命令:

    Get-MgBetaGroupSetting -GroupId $GroupId | FL Values
    

更新特定组的设置

  1. 获取要更新其设置的组的 ID:

    $groupId = (Get-MgGroup -Filter "DisplayName eq '<YourGroupName>'").Id
    
  2. 检索组的设置:

    $Setting = Get-MgBetaGroupSetting -GroupId $GroupId
    
  3. 根据需要更新组的设置:

    $params = @{
       values = @(
          @{
             name = "AllowToAddGuests"
             value = "True"
          }
       )
    }
    
  4. 然后,可以设置此设置的新值:

    Update-MgBetaGroupSetting -DirectorySettingId $Setting.Id -GroupId $GroupId -BodyParameter $params
    
  5. 可以读取此设置的值,确保已将其正确更新:

    Get-MgBetaGroupSetting -GroupId $GroupId  | FL Values
    

Cmdlet 语法参考

如需更多 Microsoft Graph PowerShell 文档,可参阅 Microsoft Entra Cmdlet

使用 Microsoft Graph 管理组设置

若要使用 Microsoft Graph 配置和管理组设置,请参阅 groupSetting 资源类型及其关联的方法。

其他阅读材料