Skip to content

Add tool generated PowerShell module#1443

Open
Gijsreyn wants to merge 4 commits intoPowerShell:mainfrom
Gijsreyn:gh-1311/main/add-msdsc-module
Open

Add tool generated PowerShell module#1443
Gijsreyn wants to merge 4 commits intoPowerShell:mainfrom
Gijsreyn:gh-1311/main/add-msdsc-module

Conversation

@Gijsreyn
Copy link
Collaborator

@Gijsreyn Gijsreyn commented Mar 22, 2026

PR Summary

This change adds the initial scaffolding for the Microsoft.PowerShell.DSC PowerShell module. It contains two public functions to generate DSC resource manifest files.

The four functions are:

  • New-DscAdaptedResourceManifest - parses class-based PowerShell DSC resources from three file types (.psd1, .ps1, or .psm1)
  • New-DscResourceManifest - combines adapted resources (via pipeline) and/or command-based DSC resource (via -Resource) into a DscResourceManifestList object.
  • Import-DscAdaptedResourceManifest - reads existing .dsc.adaptedResource.json files and returns DscAdaptedResourceManifest objects
  • Import-DscResourceManifest - reads existing .dsc.manifests.json files and returns a DscResourceManifestList object with adapted resources, command-based resources, and extensions

Both functions support pipeline input and can be chained together. For example:

New-DscAdaptedResourceManifest -Path ./MyModule/MyModule.psd1 |
    New-DscResourceManifest |
    ForEach-Object { $_.ToJson() } |
    Set-Content -Path ./MyModule/MyModule.dsc.manifests.json

# Import an existing manifest list, add a new adapted resource, and re-export
$list = Import-DscResourceManifest -Path ./MyModule/MyModule.dsc.manifests.json
Import-DscAdaptedResourceManifest -Path ./NewResource.dsc.adaptedResource.json |
    ForEach-Object { $list.AddAdaptedResource($_) }
$list.ToJson() | Set-Content -Path ./MyModule/MyModule.dsc.manifests.json

Known limitations

This is the initial implementation as a starting point. Edge cases are definitely missed, and the module will need iteration. Known areas that I can think of that are not yet handled include:

  • Complex nested class hierarchies beyond single-level inheritance (don't know if it's even possible in class-based DSC resources)
  • Resources defined across multiple files that use using module
  • Validation attributes
  • More error handling for incorrect values/properties

PR Context

Partially addresses #1311

Copilot AI review requested due to automatic review settings March 22, 2026 13:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces initial scaffolding for the Microsoft.PowerShell.DSC PowerShell module, focused on generating DSC v3 manifest content for class-based (adapted) resources and bundling them into a manifests list.

Changes:

  • Adds New-DscAdaptedResourceManifest to parse PowerShell AST for [DscResource()] classes and emit adapted resource manifest objects with embedded JSON schema.
  • Adds New-DscResourceManifest to aggregate adapted resources (pipeline) and/or command-based resources (-Resource) into a DscResourceManifestList with ToJson() serialization.
  • Adds Pester tests and fixture modules/resources covering single/multi-resource modules, inheritance/enums, and basic JSON serialization.

Reviewed changes

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

Show a summary per file
File Description
tools/Microsoft.PowerShell.DSC/Microsoft.PowerShell.DSC.psm1 Implements manifest/schema generation logic and public functions.
tools/Microsoft.PowerShell.DSC/Microsoft.PowerShell.DSC.psd1 Adds module manifest exporting the two public functions.
tools/Microsoft.PowerShell.DSC/Tests/New-DscAdaptedResourceManifest.Tests.ps1 Adds Pester coverage for adapted manifest creation, schema embedding, and pipeline input.
tools/Microsoft.PowerShell.DSC/Tests/New-DscResourceManifest.Tests.ps1 Adds Pester coverage for bundling adapted/command resources and JSON serialization.
tools/Microsoft.PowerShell.DSC/Tests/Fixtures/* Adds fixture modules/resources used by the Pester tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants