你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
用于配置组设置的 Azure Active Directory cmdlet
本文包含有关在属于 Microsoft Entra 的 Azure Active Directory (Azure AD) 中使用 PowerShell cmdlet 创建和更新组的说明。 此内容仅适用于 Microsoft 365 组(有时称为统一组)。
重要
某些设置需要 Azure Active Directory Premium P1 许可证。 有关详细信息,请参阅模板设置表。
有关如何防止非管理员用户创建安全组的详细信息,请按照 Set-MSOLCompanySettings 中所述内容设置 Set-MsolCompanySettings -UsersPermissionToCreateGroupsEnabled $False
。
Microsoft 365 组设置使用 Settings 对象和 SettingsTemplate 对象配置。 起初,目录中不会显示任何设置对象,因为目录配置为默认设置。 若要更改默认设置,必须使用设置模板创建新的设置对象。 设置模板由 Microsoft 定义。 有几个不同的设置模板。 若要配置目录的 Microsoft 365 组设置,请使用名为“Group.Unified”的模板。 若要针对单个组配置 Microsoft 365 组设置,请使用名为“Group.Unified.Guest”的模板。 此模板用于管理对 Microsoft 365 组的来宾访问权限。
这些 Cmdlet 属于 Azure Active Directory PowerShell V2 模块。 有关如何在计算机上下载和安装模块的说明,请参阅文章 Azure Active Directory PowerShell Version 2(Azure Active Directory PowerShell 版本 2)。 可以从 PowerShell 库安装模块的版本 2 发行版。
注意
即使适当设置限制将来宾添加到 Microsoft 365 组,管理员仍可将来宾用户添加到 Microsoft 365 组。 此设置将限制非管理员用户将来宾用户添加到 Microsoft 365 组。
安装 PowerShell cmdlet
在运行 PowerShell 命令之前,请确保卸载任何旧版本的 Azure Active Directory PowerShell for Graph、Windows PowerShell 模块,并安装 Azure Active Directory PowerShell for Graph - 公共预览版(比 2.0.0.137 更新)。
以管理员身份打开 Windows PowerShell 应用。
卸载任何以前版本的 AzureADPreview。
Uninstall-Module AzureADPreview Uninstall-Module azuread
安装最新版本的 AzureADPreview。
Install-Module AzureADPreview
在目录级别创建设置
这些步骤在目录级别创建设置,这些设置适用于目录中的所有 Microsoft 365 组。 Get-AzureADDirectorySettingTemplate cmdlet 仅在 Azure AD PowerShell for Graph 预览模块中可用。
在 DirectorySettings cmdlet 中,必须指定要使用的 SettingsTemplate 的 ID。 如果不知道此 ID,此 cmdlet 将返回所有设置模板的列表:
Get-AzureADDirectorySettingTemplate
此 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 ...
若要添加使用准则 URL,首先需获取定义使用准则 URL 值的 SettingsTemplate 对象,即 Group.Unified 模板:
$TemplateId = (Get-AzureADDirectorySettingTemplate | where { $_.DisplayName -eq "Group.Unified" }).Id $Template = Get-AzureADDirectorySettingTemplate | where -Property Id -Value $TemplateId -EQ
接下来,创建基于该模板的新设置对象:
$Setting = $Template.CreateDirectorySetting()
然后使用新值更新设置对象。 下面的两个示例更改了使用准则值并启用了敏感度标签。 根据需要在模板中设置这些设置或任何其他设置:
$Setting["UsageGuidelinesUrl"] = "https://guideline.example.com" $Setting["EnableMIPLabels"] = "True"
然后应用设置:
New-AzureADDirectorySetting -DirectorySetting $Setting
可以使用以下命令读取值:
$Setting.Values
在目录级别更新设置
若要在设置模板中更新 UsageGuideLinesUrl 的值,请从 Azure AD 读取当前设置,否则我们可能最终会覆盖 UsageGuideLinesUrl 以外的现有设置。
从 Group.Unified SettingsTemplate 获取当前设置:
$Setting = Get-AzureADDirectorySetting | ? { $_.DisplayName -eq "Group.Unified"}
检查当前设置:
$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
若要删除 UsageGuideLinesUrl 的值,请将 URL 编辑为空字符串:
$Setting["UsageGuidelinesUrl"] = ""
将更新保存到目录:
Set-AzureADDirectorySetting -Id $Setting.Id -DirectorySetting $Setting
模板设置
以下是 Group.Unified SettingsTemplate 中定义的设置。 除非另有说明,否则这些功能都需要 Azure Active Directory Premium P1 许可证。
设置 | 说明 |
---|---|
|
一个标志,指明是否允许非管理员用户在目录中创建 Microsoft 365 组。 此设置不需要 Azure Active Directory Premium P1 许可证。 |
|
安全组的 GUID,允许该组的成员创建 Microsoft 365 组,即使 EnableGroupCreation == false。 |
|
组使用准则链接。 |
|
以逗号分隔的分类说明列表。 ClassificationDescriptions 的值仅以此格式有效: $setting["ClassificationDescriptions"] ="Classification:Description,Classification:Description" 其中,Classification 与 ClassificationList 中的条目匹配。 当 EnableMIPLabels == True 时,此设置不适用。 属性 ClassificationDescriptions 的字符限制为 300,不能对逗号进行转义。 |
|
如果未指定,则为要用作组的默认分类的分类。 当 EnableMIPLabels == True 时,此设置不适用。 |
|
最大长度为 64 个字符的字符串,用于定义为 Microsoft 365 组配置的命名约定。 有关详细信息,请参阅对 Microsoft 365 组强制实施命名策略。 |
|
逗号分隔字符串,用于列出不允许用户在组名称或别名中使用的短语。 有关详细信息,请参阅对 Microsoft 365 组强制实施命名策略。 |
|
已否决。 请勿使用。 |
|
一个布尔值,该值指示来宾用户是否可以作为组的所有者。 |
|
一个布尔值,指示来宾用户是否可以访问 Microsoft 365 组的内容。 此设置不需要 Azure Active Directory Premium P1 许可证。 |
|
指向来宾使用指南的链接的 URL。 |
|
一个布尔值,该值指示是否允许将来宾添加到此目录。 如果 EnableMIPLabels 设置为 True 且某个来宾策略与分配给组的敏感性标签相关联,则此设置可能会被重写,变成只读。 如果在组织级别将 AllowToAddGuests 设置设为 False,则会忽略组级别的任何 AllowToAddGuests 设置。 如果希望仅对几个组启用来宾访问,则必须在组织级别将 AllowToAddGuests 设为 true,然后针对特定组有选择地禁用它。 |
|
一个逗号分隔列表,用于列出可以应用于 Microsoft 365 组的有效分类值。 当 EnableMIPLabels == True 时,此设置不适用。 |
|
一个标记,表明在 Microsoft Purview 合规门户发布的敏感性标签是否适用于 Microsoft 365 组。 有关详细信息,请参阅为 Microsoft 365 组分配敏感度标签。 |
|
使管理员可以新建 Microsoft 365 组而无需在请求负载中设置 groupWritebackConfiguration 资源类型的标志。 在 Azure AD Connect 中配置组写回时,此设置适用。 “NewUnifiedGroupWritebackDefault”是一个全局 Microfot 365 组设置。 默认值为 true。 将此设置值更新为 false 时,将会更改新建的 Microsoft 365 组的默认写回行为,而不会更改现有 Microsoft 365 组的 isEnabled 属性值。 组管理员需要显式更新组 isEnabled 属性值,才能更改现有 Microsoft 365 组的写回状态。 |
示例:在目录级别为组配置来宾策略
获取所有设置模板:
Get-AzureADDirectorySettingTemplate
若要在目录级别为组设置来宾策略,需要 Group.Unified 模板
$Template = Get-AzureADDirectorySettingTemplate | where -Property Id -Value "62375ab9-6b52-47ed-826b-58e47e0e304b" -EQ
接下来,创建基于该模板的新设置对象:
$Setting = $template.CreateDirectorySetting()
然后,更新 AllowToAddGuests 设置
$Setting["AllowToAddGuests"] = $False
然后应用设置:
Set-AzureADDirectorySetting -Id (Get-AzureADDirectorySetting | where -Property DisplayName -Value "Group.Unified" -EQ).id -DirectorySetting $Setting
可以使用以下命令读取值:
$Setting.Values
在目录级别读取设置
如果知道要检索的设置的名称,可以使用以下 cmdlet 检索当前的设置值。 在此示例中,我们要检索名为“UsageGuidelinesUrl”的设置的值。
(Get-AzureADDirectorySetting).Values | Where-Object -Property Name -Value UsageGuidelinesUrl -EQ
这些步骤在目录级别读取设置,这些设置适用于目录中的所有 Office 组。
读取所有现有的目录设置:
Get-AzureADDirectorySetting -All $True
此 cmdlet 返回所有目录设置的列表:
Id DisplayName TemplateId Values -- ----------- ---------- ------ c391b57d-5783-4c53-9236-cefb5c6ef323 Group.Unified 62375ab9-6b52-47ed-826b-58e47e0e304b {class SettingValue {...
读取特定组的所有设置:
Get-AzureADObjectSetting -TargetObjectId ab6a3887-776a-4db7-9da4-ea2b0d63c504 -TargetType Groups
使用设置 ID GUID 读取特定目录设置对象的所有目录设置值:
(Get-AzureADDirectorySetting -Id 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-AzureADDirectorySetting –Id c391b57d-5783-4c53-9236-cefb5c6ef323c
创建特定组的设置
搜索名为“Groups.Unified.Guest”的设置模板
Get-AzureADDirectorySettingTemplate 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 ...
检索 Groups.Unified.Guest 模板的模板对象:
$Template1 = Get-AzureADDirectorySettingTemplate | where -Property Id -Value "08d542b9-071f-4e16-94b0-74abb372e3d9" -EQ
从模板创建新的设置对象:
$SettingCopy = $Template1.CreateDirectorySetting()
将设置设为所需的值:
$SettingCopy["AllowToAddGuests"]=$False
获取要对其应用此设置的组的 ID:
$groupID= (Get-AzureADGroup -SearchString "YourGroupName").ObjectId
在目录中为所需组创建新设置:
New-AzureADObjectSetting -TargetType Groups -TargetObjectId $groupID -DirectorySetting $SettingCopy
若要验证设置,请运行以下命令:
Get-AzureADObjectSetting -TargetObjectId $groupID -TargetType Groups | fl Values
更新特定组的设置
- 获取要更新其设置的组的 ID:
$groupID= (Get-AzureADGroup -SearchString "YourGroupName").ObjectId
- 检索组的设置:
$Setting = Get-AzureADObjectSetting -TargetObjectId $groupID -TargetType Groups
- 根据需要更新组的设置,例如:
$Setting["AllowToAddGuests"] = $True
- 然后,获取此特定组的设置的 ID:
将会获得如下所示的响应:Get-AzureADObjectSetting -TargetObjectId $groupID -TargetType Groups
Id DisplayName TemplateId Values -- ----------- ----------- ---------- 2dbee4ca-c3b6-4f0d-9610-d15569639e1a Group.Unified.Guest 08d542b9-071f-4e16-94b0-74abb372e3d9 {class SettingValue {...
- 然后,可以设置此设置的新值:
Set-AzureADObjectSetting -TargetType Groups -TargetObjectId $groupID -Id 2dbee4ca-c3b6-4f0d-9610-d15569639e1a -DirectorySetting $Setting
- 可以读取此设置的值,确保已将其正确更新:
Get-AzureADObjectSetting -TargetObjectId $groupID -TargetType Groups | fl Values
Cmdlet 语法参考
如需更多 Azure Active Directory PowerShell 文档,可参阅 Azure Active Directory Cmdlet。
使用 Microsoft Graph 管理组设置
若要使用 Microsoft Graph 配置和管理组设置,请参阅 groupSetting 资源类型及其关联方法。