用於設定群組設定的 Microsoft Entra Cmdlet

本文包含使用 PowerShell Cmdlet 在 Microsoft Entra 識別符中建立和更新群組的指示,這是 Microsoft Entra 的一部分。 此內容僅適用於 Microsoft 365 群組(有時稱為統一群組)。

重要

某些設定需要 Microsoft Entra ID P1 授權。 如需詳細資訊,請參閱 範本設定 數據表。

如需如何防止非系統管理員使用者建立安全組的詳細資訊,請將 屬性設定AllowedToCreateSecurityGroups為 False,如 Update-MgPolicyAuthorizationPolicy 中所述

Microsoft 365 群組設定是使用 設定 物件和 設定 Template 物件來設定。 一開始,您不會在目錄中看到任何 設定 對象,因為您的目錄已使用預設設定進行設定。 若要變更預設設定,您必須使用設定範本建立新的設定物件。 設定 範本是由 Microsoft 定義。 有數個不同的設定範本。 若要為您的目錄設定 Microsoft 365 群組設定,請使用名為 “Group.Unified” 的範本。 若要在單一群組上設定 Microsoft 365 群組設定,請使用名為 “Group.Unified.Guest” 的範本。 此範本可用來管理 Microsoft 365 群組的來賓存取權。

Cmdlet 是 Microsoft Graph PowerShell 模組的一部分。 如需如何在計算機上安裝模組的指示,請參閱 安裝 Microsoft Graph PowerShell SDK

重要

Azure AD PowerShell 計劃於 2024 年 3 月 30 日淘汰。 若要深入瞭解,請閱讀 淘汰更新。 建議您移轉至 Microsoft Graph PowerShell ,以與 Microsoft Entra ID (先前稱為 Azure AD) 互動。 Microsoft Graph PowerShell 允許存取所有 Microsoft Graph API,並可在 PowerShell 7 上使用。 如需常見移轉查詢的解答,請參閱 移轉常見問題

注意

將來賓新增限制為 Microsoft 365 群組 的設定,系統管理員仍會將來賓使用者新增至 Microsoft 365 群組。 此設定會限制非系統管理員用戶將來賓使用者新增至 Microsoft 365 群組。

安裝 PowerShell Cmdlets

安裝 Microsoft Graph Cmdlet,如安裝 Microsoft Graph PowerShell SDK 中所述

  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. 在 Directory 設定 Cmdlet 中,您必須指定您想要使用的 設定 Template 識別符。 如果您不知道此識別碼,此 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 值的 設定 Template 物件;也就是 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 設定 Template 取得目前的設定:

    $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 設定 Template 中定義的設定。 除非另有指示,否則這些功能需要 Microsoft Entra ID P1 授權。

設定 說明
  • EnableGroupCreation
  • 類型:布林值
  • 預設值:True
旗標,指出非系統管理員使用者是否允許在目錄中建立 Microsoft 365 群組。 此設定不需要 Microsoft Entra ID P1 授權。
  • GroupCreationAllowedGroupId
  • 類型:字串
  • 默認值:“”
允許成員建立 Microsoft 365 群組之安全組的 GUID,即使 EnableGroupCreation == false。
  • UsageGuidelinesUrl
  • 類型:字串
  • 默認值:“”
群組使用方針的連結。
  • ClassificationDescriptions
  • 類型:字串
  • 默認值:“”
分類描述的逗號分隔清單。 ClassificationDescriptions 的值僅能以下列格式有效:
$setting[“ClassificationDescriptions”] =“Classification:Description,Classification:Description”
其中 Classification 符合 ClassificationList 中的專案。
當 EnableMIPLabels == True 時,不會套用此設定。
屬性 ClassificationDescriptions 的字元限制為 300,而且無法逸出逗號,
  • DefaultClassification
  • 類型:字串
  • 默認值:“”
如果未指定任何分類,則做為群組的默認分類。
當 EnableMIPLabels == True 時,不會套用此設定。
  • PrefixSuffixNamingRequirement
  • 類型:字串
  • 默認值:“”
長度上限為 64 個字元的字串,定義為 Microsoft 365 群組設定的命名慣例。 如需詳細資訊,請參閱 為 Microsoft 365 群組強制執行命名原則。
  • CustomBlockedWordsList
  • 類型:字串
  • 默認值:“”
用戶不允許在組名或別名中使用以逗號分隔的片語字串。 如需詳細資訊,請參閱 為 Microsoft 365 群組強制執行命名原則。
  • EnableMSStandardBlockedWords
  • 類型:布林值
  • 默認值:“False”
已取代。 請勿使用。
  • AllowGuestsToBeGroupOwner
  • 類型:布林值
  • 預設值:False
布爾值,指出來賓使用者是否可以是群組的擁有者。
  • AllowGuestsToAccessGroups
  • 類型:布林值
  • 預設值:True
布爾值,指出來賓使用者是否可以存取 Microsoft 365 群組內容。 此設定不需要 Microsoft Entra ID P1 授權。
  • GuestUsageGuidelinesUrl
  • 類型:字串
  • 默認值:“”
來賓使用指導方針連結的 URL。
  • AllowToAddGuests
  • 類型:布林值
  • 預設值:True
布爾值,指出是否允許將來賓新增至此目錄。
如果 EnableMIPLabels 設定為 True ,且來賓原則與指派給群組的敏感度標籤相關聯,則此設定可能會覆寫並變成只讀。
如果 AllowToAddGuests 設定在組織層級設定為 False,則會忽略群組層級的任何 AllowToAddGuests 設定。 如果您想要只針對少數群組啟用來賓存取,您必須在組織層級將AllowToAddGuests設定為 true,然後選擇性地針對特定群組停用它。
  • ClassificationList
  • 類型:字串
  • 默認值:“”
可套用至 Microsoft 365 群組之有效分類值的逗號分隔清單。
當 EnableMIPLabels == True 時,不會套用此設定。
  • EnableMIPLabels
  • 類型:布林值
  • 默認值:“False”
旗標,指出 Microsoft Purview 合規性入口網站 中發佈的敏感度標籤是否可以套用至 Microsoft 365 群組。 如需詳細資訊,請參閱 指派 Microsoft 365 群組的敏感度標籤。
  • NewUnifiedGroupWritebackDefault
  • 類型:布林值
  • 默認值:“True”
旗標,可讓系統管理員建立新的 Microsoft 365 群組,而不需在要求承載中設定 groupWritebackConfiguration 資源類型。 當 Microsoft Entra 連線 中設定群組回寫時,此設定適用。 “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. 使用 設定 識別元 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. 取得您要套用此設定的群組識別碼:

    $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. 取得您要更新其設定的群組識別碼:

    $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 Cmdlet 找到更多 Microsoft Graph PowerShell 檔

使用 Microsoft Graph 管理群組設定

若要使用 Microsoft Graph 設定和管理群組設定,請參閱 groupSetting 資源類型和 其相關聯的方法。

延伸閱讀