Skip to content

Add Group Policy template adapter - #1686

Open
Steve Lee (SteveL-MSFT) wants to merge 1 commit into
mainfrom
stevel-msft-group-policy-template-adapter
Open

Add Group Policy template adapter#1686
Steve Lee (SteveL-MSFT) wants to merge 1 commit into
mainfrom
stevel-msft-group-policy-template-adapter

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

Windows Group Policy templates vary by machine, so DSC needs a dynamic adapter that discovers the locally installed ADMX definitions and exposes them as manageable resources.

This adds the Rust-based Microsoft.Adapter/GroupPolicyTemplate adapter. It scans %SystemRoot%\PolicyDefinitions, resolves localized ADML strings, groups policies into adapted GPO.<parentCategory>/<category> resources, and generates JSON Schema for policy toggles and ADMX child elements. Get and set operations map user and machine scope to HKCU and HKLM while preserving ADMX registry value types, delete semantics, policy class restrictions, and enabled/disabled value lists.

Pester coverage verifies adapter discovery against installed ADMX files and includes an elevated, current-user-only mutation test with state restoration. Rust unit tests cover naming, binary parsing, and scope-to-hive mapping.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 21, 2026 23:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Rust-based DSC adapter (Microsoft.Adapter/GroupPolicyTemplate) that discovers locally installed Windows Group Policy ADMX/ADML templates and exposes them as dynamically generated DSC resources, with get/set backed by registry operations.

Changes:

  • Adds a new adapters/group_policy_template crate implementing ADMX parsing, schema generation, and registry-backed get/set.
  • Registers the adapter in the workspace (members/default-members/Windows set) and adds required dependencies (roxmltree, Windows globalization feature).
  • Adds Pester + Rust unit tests to validate discovery and a basic current-user mutation scenario.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Cargo.toml Adds the new adapter crate to workspace membership and adds dependencies/features needed for XML + locale support.
Cargo.lock Locks the new adapter crate and roxmltree dependency.
adapters/group_policy_template/Cargo.toml Defines the new adapter crate and its dependencies/targets.
adapters/group_policy_template/src/main.rs Implements adapter CLI dispatch (list/get/set), stdout output, and structured JSON error reporting.
adapters/group_policy_template/src/admx.rs Implements ADMX/ADML discovery, locale resolution, resource modeling, and JSON Schema generation.
adapters/group_policy_template/src/registry.rs Implements policy state read/write logic by mapping scope to HKCU/HKLM and applying registry value semantics.
adapters/group_policy_template/locales/en-us.toml Adds i18n strings for user-facing adapter messages.
adapters/group_policy_template/group_policy_template.dsc.resource.json Adds the DSC adapter manifest wiring list/get/set to the new executable.
adapters/group_policy_template/tests/group_policy_template.tests.ps1 Adds Pester coverage for discovery and an elevated current-user mutation test with restoration.
adapters/group_policy_template/.project.data.json Registers the adapter in repo metadata/build packaging (binary + copy files).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +107 to +122
fn read_enabled(policy: &Policy, scope: &str) -> Result<Option<bool>, AdapterError> {
if state_matches(policy, scope, true)? {
Ok(Some(true))
} else if state_matches(policy, scope, false)? {
Ok(Some(false))
} else {
Err(AdapterError::Resource(
t!(
"registry.unrecognizedValue",
key = policy.key,
value_name = policy.value_name.as_deref().unwrap_or_default()
)
.to_string(),
))
}
}
Comment on lines +142 to +145
for entry in entries {
let path = entry
.map_err(|error| AdapterError::Resource(error.to_string()))?
.path();
$LASTEXITCODE | Should -Be 0
$admxFiles.Count | Should -BeGreaterThan 0
$resources.Count | Should -BeGreaterThan 0
$resources.requireAdapter | Should -Contain $adapterType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants