原則 CSP - LocalUsersAndGroups

設定

領域 版本 適用的作業系統
✅ 裝置
❌ 使用者
✅ 專業版
✅ 企業版
✅ 教育版
✅ Windows SE
✅ IoT 企業版 / IoT 企業版 LTSC
✅Windows 10,版本 2009 [10.0.19042] 和更新版本
./Device/Vendor/MSFT/Policy/Config/LocalUsersAndGroups/Configure

此設定可讓系統管理員管理裝置上的本機群組。 可能的設定:

  1. 更新群組成員資格:更新群組,並透過 『U』 動作新增和/或移除成員。 使用 Update 時,原則中未指定的現有群組成員會維持不變。
  2. 取代群組成員資格:透過 『R』 動作取代群組成員資格來限制群組。 使用 Replace 時,現有的群組成員資格會由 add 成員區段中指定的成員清單取代。 此選項的運作方式與限制群組相同,而且會移除原則中未指定的任何群組成員。

注意

如果使用 Replace 和 Update 設定相同的群組,則 Replace 將會獲勝。

注意

RestrictedGroups/ConfigureGroupMembership 原則設定也可讓您設定成員 (使用者或 Microsoft Entra 群組) Windows 10 本機群組。 不過,它只允許以新成員完整取代現有的群組,而且不允許選擇性新增或移除。

從 Windows 10 20H2 版開始,建議使用 LocalUsersAndGroups 原則,而不是 RestrictedGroups 原則。 不支援將這兩個原則套用至相同的裝置,而且可能會產生無法預期的結果。

描述架構屬性:

屬性名稱 屬性值
格式 chr (字串)
存取類型 新增、刪除、取得、取代

允許的值:


展開以查看架構 XML
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
  <xs:simpleType name="name">
    <xs:restriction base="xs:string">
      <xs:maxLength value="255" />
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="accessgroup">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="group" minOccurs="1" maxOccurs="1">
          <xs:annotation>
            <xs:documentation>Group Configuration Action</xs:documentation>
          </xs:annotation>
          <xs:complexType>
            <xs:attribute name="action" type="name" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="add" minOccurs="0" maxOccurs="unbounded">
          <xs:annotation>
            <xs:documentation>Group Member to Add</xs:documentation>
          </xs:annotation>
          <xs:complexType>
            <xs:attribute name="member" type="name" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="remove" minOccurs="0" maxOccurs="unbounded">
          <xs:annotation>
            <xs:documentation>Group Member to Remove</xs:documentation>
          </xs:annotation>
          <xs:complexType>
            <xs:attribute name="member" type="name" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="property" minOccurs="0" maxOccurs="unbounded">
          <xs:annotation>
            <xs:documentation>Group property to configure</xs:documentation>
          </xs:annotation>
          <xs:complexType>
            <xs:attribute name="desc" type="name" use="required" />
            <xs:attribute name="value" type="name" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="desc" type="name" use="required" />
    </xs:complexType>
  </xs:element>
  <xs:element name="GroupConfiguration">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="accessgroup" minOccurs="0" maxOccurs="unbounded">
          <xs:annotation>
            <xs:documentation>Local Group Configuration</xs:documentation>
          </xs:annotation>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

範例

以下是組態的原則定義 XML 範例:

<GroupConfiguration>
    <accessgroup desc = "">
        <group action = ""/>
            <add member = ""/>
            <remove member = ""/>
    </accessgroup>
</GroupConfiguration>

其中:

  • <accessgroup desc>:指定要設定之本機群組的名稱或 SID。 如果您指定 SID, 則會使用 LookupAccountSid API 將 SID 轉譯為有效的組名。 如果您指定名稱, 則會使用LookupAccountName API來查閱群組並驗證名稱。 如果名稱/SID 查閱失敗,則會略過群組,並處理 XML 檔案中的下一個群組。 如果發生多個錯誤,最後一個錯誤會在原則處理結束時傳回。

  • <group action>:指定要對本機群組採取的動作,這可以是 Update 和 Restrict,由您和 R 表示:

    • Update。 此動作必須用來維持目前的群組成員資格不變,以及新增或移除特定群組的成員。
    • 限制。 此動作必須用來將目前的成員資格取代為新指定的群組。 此動作提供與 RestrictedGroups/ConfigureGroupMembership 原則設定相同的功能。
  • <add member>:指定要設定之成員的 SID 或名稱。

  • <remove member>:指定要從指定群組移除之成員的 SID 或名稱。

    注意

    指定使用者帳戶的成員名稱時,您必須使用下列格式 - AzureAD\userUPN。 例如,“AzureAD\user1@contoso.com” 或 “AzureAD\user2@contoso.co.uk”。 若要新增 Microsoft Entra 群組,您必須指定 Microsoft Entra 群組 SID。 Microsoft Entra 此原則不支援組名。 如需詳細資訊,請 參閱LookupAccountNameA函式

如需如何建立自定義配置檔的資訊,請參閱在 Intune 中使用 Windows 10 裝置的自定義設定。

重要

  • <add member><remove member> 可以使用 Microsoft Entra SID 或使用者的名稱。 若要使用此原則新增或移除 Microsoft Entra 組,您必須使用群組的 SID。 Microsoft Entra 群組 SID 可以使用群組的圖形 API 來取得。 SID 存在於 屬性中 securityIdentifier
  • 在 或 <remove member><add member>指定 SID 時,會新增成員 SID,而不會嘗試解析它們。 因此,在指定 SID 時請非常小心,以確保它正確無誤。
  • <remove member> 對 R (限制) 動作無效,如果有的話,將會忽略。
  • XML 中的清單會依照指定的順序處理,但 R 動作除外,最後會進行處理以確保它們會獲勝。 這也表示,如果群組存在多次,且具有不同的新增/移除值,則所有群組都會依照其存在的順序進行處理。

範例 1:焦點 Microsoft Entra ID。

下列範例會使用 SID S-1-5-21-22222222-33333333333333-444444444-500 更新內建系統管理員群組,並 Microsoft Entra 帳戶 “bob@contoso.com” 和 a Microsoft Entra 在已加入 Microsoft Entra 計算機上使用 SID S-1-12-1-11111111111-22222222-333333333333-4444444444444 的群組。

<GroupConfiguration>
    <accessgroup desc = "S-1-5-21-2222222222-3333333333-4444444444-500">
        <group action = "U" />
        <add member = "AzureAD\bob@contoso.com"/>
        <add member = "S-1-12-1-111111111-22222222222-3333333333-4444444444"/>
    </accessgroup>
</GroupConfiguration>

範例 2:以 Microsoft Entra 用戶帳戶取代/限制內建系統管理員群組。

注意

使用 'R' 取代選項以 SID S-1-5-21-22222222-333333333333333333-44444444-500 設定內建 Administrators 群組時,您應該一律將系統管理員指定為成員加上任何其他自定義成員。 這是必要的,因為內建系統管理員必須一律是系統管理員群組的成員。

<GroupConfiguration>
    <accessgroup desc = "S-1-5-21-2222222222-3333333333-4444444444-500">
        <group action = "R" />
        <add member = "AzureAD\bob@contoso.com"/>
        <add member = "Administrator"/>
    </accessgroup>
</GroupConfiguration>

範例 3:在混合式加入的計算機上新增和移除群組成員的更新動作。

下列範例示範如何使用 SID S-1-5-21-222222222-3333333333333333-444444444-500) 更新本機群 (組—使用其名稱 (Contoso\ITAdmins) 新增 AD 網域群組, 透過 SID (S-1-12-1-1-111111111-2222222222-3333333333333333-444444444333-4444333-444441111-22222222-3333333333333-4444444) 新增 Microsoft Entra 群組,並移除 (客體) 的本機帳戶。

<GroupConfiguration>
    <accessgroup desc = "S-1-5-21-2222222222-3333333333-4444444444-500">
        <group action = "U" />
        <add member = "Contoso\ITAdmins"/>
        <add member = "S-1-12-1-111111111-22222222222-3333333333-4444444444"/>
        <remove member = "Guest"/>
    </accessgroup>
</GroupConfiguration>

注意

當 Microsoft Entra 群組 SID 新增至本機群組時,只會針對 Windows 10 裝置上的下列已知群組評估 Microsoft Entra 帳戶登入許可權:

  • 管理員
  • 使用者
  • 訪客
  • 電源使用者
  • 遠端桌面使用者
  • 遠端管理使用者

常見問題集

本節提供有關 LocalUsersAndGroups 原則 CSP 的一些常見問題解答。

如果我不小心從 Administrators 群組移除內建的 Administrator SID,會發生什麼事?

基於安全性考慮,在 SAM/OS 層級封鎖從內建 Administrators 群組移除內建的系統管理員帳戶。 嘗試這樣做會導致失敗,並出現下列錯誤:

錯誤碼 符號名稱 錯誤描述 標頭
0x55b (十六进制)
1371 (12 月)
ERROR_SPECIAL_ACCOUNT 無法在內建帳戶上執行此作業。 winerror.h

使用 R (Restrict) 動作來設定內建 Administrators 群組時,請在 中指定內建的系統管理員帳戶 SID/Name <add member> 以避免發生此錯誤。

我可以新增已經存在的成員嗎?

是,您可以新增已經是群組成員的成員。 這不會對群組造成任何變更,也不會產生任何錯誤。

如果成員不是群組的成員,我可以移除該成員嗎?

是,即使成員不是群組的成員,您還是可以移除該成員。 這不會對群組造成任何變更,也不會產生任何錯誤。

如何將網域群組新增為本機群組的成員?

若要將網域群組新增為本機群組的成員,請在本機群組中 <add member> 指定網域群組。 使用完整帳戶名稱 (例如,domain_name\group_name) ,而不是隔離名稱 (例如,group_name) 以获得最佳结果。 如需詳細資訊 ,請參閱LookupAccountNameA函 式。

我可以將多個 LocalUserAndGroups 原則/XML 套用至相同的裝置嗎?

否,這是不允許的。 嘗試這麼做會導致 Intune 發生衝突。

如果我指定不存在的組名,會發生什麼事?

將會略過無效的組名或 SID。 將會套用原則的有效部分,而且會在處理結束時傳回錯誤。 此行為與內部部署 AD GPP (群組原則 喜好設定) LocalUsersAndGroups 原則一致。 同樣地,將會略過無效的成員名稱,並在結尾傳回錯誤,以通知並非所有設定都已成功套用。

如果我在相同的 XML 中指定 R 和 U,會發生什麼事?

如果您在相同的 XML 中同時指定 R 和 U,R (Restrict) 動作會優先於 U (Update) 。 因此,如果群組在 XML 中出現兩次,一次是使用您,一次是使用 R,R 動作就會成功。

如何? 檢查用戶端裝置上套用的原則結果嗎?

在用戶端裝置上套用原則之後,您可以調查事件記錄檔以檢閱結果:

  1. 開啟 事件檢視器 (eventvwr.exe) 。
  2. 流覽至應用程式和服務記錄>Microsoft>Windows>DeviceManagement-Enterprise-Diagnostics-Provider>管理員
  3. LocalUsersAndGroups搜尋字串以檢閱相關詳細數據。

如何針對名稱/SID 查閱 API 進行疑難解答?

若要針對名稱/SID 查閱 API 進行疑難解答:

  1. 執行 列命令,在用戶端裝置上啟用lsp.log:

    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name LspDbgInfoLevel -Value 0x800 -Type dword -Force
    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name LspDbgTraceOptions -Value 0x1 -Type dword -Force
    

    隨即會顯示 (C:\windows\debug\lsp.log) 的lsp.log 檔案。 此記錄檔會追蹤 SID-Name 解析。

  2. 執行下列命令來關閉記錄:

    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name LspDbgInfoLevel -Value 0x0 -Type dword -Force
    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name LspDbgTraceOptions -Value 0x0 -Type dword -Force
    

原則設定服務提供者