Compartilhar via

用于配置组设置的 Microsoft Entra cmdlet

本文包含有关使用 PowerShell cmdlet 在Microsoft Entra ID(Microsoft Entra的一部分)中创建和更新组的说明。 此内容仅适用于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

注意事项

即使启用了阻止将来宾添加到Microsoft 365组的限制,管理员仍可以添加来宾用户。 这样的限制仅对非管理员用户有效。

安装 PowerShell cmdlet

请按照安装 Microsoft Graph PowerShell SDK中所述的方法安装 Microsoft Graph cmdlet。

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

  2. 安装 Microsoft Graph 命令集。

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

    Install-Module Microsoft.Graph.Beta -Scope AllUsers
    

连接到Microsoft Graph

在运行本文中的任何 Get-Mg*New-Mg*Update-Mg* cmdlet 之前,必须先进行身份验证才能与 Microsoft Graph。

登录

Connect-MgGraph -Environment China -ClientId 'YOUR_CLIENT_ID' -TenantId 'YOUR_TENANT_ID' -Scopes "Directory.ReadWrite.All"

系统会提示你登录并同意所需的权限。

  1. 验证连接

    Get-MgContext
    

    此命令确认已登录并显示当前选定的Microsoft Graph配置文件。

  2. 本文中的一些示例使用 Microsoft Graph beta API。 切换用户配置文件:

    Select-MgProfile -Name "beta"
    

注意事项

如果未运行Connect-MgGraphGet-Mg*New-Mg*Update-Mg*则本文档中的所有命令都将失败。

在目录级别创建设置

这些步骤在目录级别创建设置,这些设置适用于目录中的所有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. 统一的模板:

    $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 许可证。

设置 说明
启用群组创建
类型:Boolean
默认值:True
此标志指示非admin 用户是否可以在目录中创建Microsoft 365组。 此设置不需要Microsoft Entra ID P1 许可证。
GroupCreationAllowedGroupId
类型:String
默认值:""
即使在EnableGroupCreation == false的情况下,允许成员创建Microsoft 365组的安全组的GUID。
UsageGuidelinesUrl
类型:String
默认值:""
指向小组使用准则的链接.
分类描述
类型:String
默认值:""
以逗号分隔的分类说明列表。 ClassificationDescriptions 的值仅对以下格式有效:
$setting["ClassificationDescriptions"] ="Classification:Description,Classification:Description"
其中,Classification 与 ClassificationList 中的条目匹配。
EnableMIPLabels == True 时,此设置不适用。
属性 ClassificationDescriptions 的字符限制为 300,且逗号不能被转义。
默认分类
类型:String
默认值:""
用作组的默认分类的分类,如果未指定的话。
EnableMIPLabels == True 时,此设置不适用。 仅当ClassificationList在同一调用中被设置时,才能设置此值。
PrefixSuffixNamingRequirement
类型:String
默认值:""
最大长度为 64 个字符的字符串,用于定义为Microsoft 365组配置的命名约定。 有关详细信息,请参阅实施 Microsoft 365 组命名策略
CustomBlockedWordsList
类型:String
默认值:""
逗号分隔字符串,用于列出不允许用户在组名称或别名中使用的短语。 有关详细信息,请参阅 实施 Microsoft 365 组命名策略
启用MS标准阻止词
类型:Boolean
默认值:False
已弃用。 请不要使用。
允许来宾成为组拥有者
类型:Boolean
默认值:False
一个布尔值,该值指示来宾用户是否可以作为组的所有者。
允许访客访问组
类型:Boolean
默认值:True
布尔值指示是否允许来宾用户访问Microsoft 365组的内容。 此设置不需要Microsoft Entra ID P1 许可证。
访客使用指南网址
类型:String
默认值:""
来宾使用指南链接的 URL。
允许添加访客
类型:Boolean
默认值:True
一个布尔值,该值指示是否允许将来宾添加到此目录。
如果 EnableMIPLabels 设置为 True,并且有来宾策略与分配给该组的敏感性标签相关联,该设置可能会被重写,并变为只读。
如果在组织级别将 AllowToAddGuests 设置设为 False,则会忽略组级别的任何 AllowToAddGuests 设置。 要仅对几个组启用访客访问,必须在组织级别将 AllowToAddGuests 设为 True,然后针对特定组有选择地禁用该功能。
ClassificationList
类型:String
默认值:""
可用于 Microsoft 365 组的有效分类值的逗号分隔列表。
当 EnableMIPLabels == True 时,此设置不适用。
EnableMIPLabels
类型:Boolean
默认值:False
指示是否可以将Microsoft Purview门户中发布的敏感标签应用于Microsoft 365组的标志。
新统一组回写默认值
类型:Boolean
默认值: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 Entra Cmdlets 找到更多Microsoft Graph PowerShell 文档。

使用Microsoft Graph管理组设置

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

其他阅读材料