DSC custom resource using Classes - Each class in separate file

Tagged: ,

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Bor Bor 1 year, 3 months ago.

  • Author
  • #26906
    Profile photo of Bor

    all examples of custom modules with DSC resources with PowerShell Classes have all classes (all resources) in a single psm1 file. Please is it possible to put each class in separate file?

    I know that dot notation is old concept but it is very handy for custom modules (advanced functions with manifest) because I can put each function in separate ps1 file and use dot notation in psm1 file to include all files (all functions). I tried this approach with classes in order to put each DSC resource in separate file but this is not working.

    Thank you.

  • #26912
    Profile photo of Dave Wyatt
    Dave Wyatt

    At the moment, the classes need to be in the same psm1 file. However, this is feedback that the PowerShell team has already received, and they may make it possible to split the classes out into multiple files at some point.

    The reason for this is PowerShell needs to be able to find the classes quickly and read their schema without having to actually import the module (so Get-DscResource works, and you get intellisense / etc when authoring a configuration), and at the moment, it only looks at the file referenced by the RootModule line of the module manifest to find these classes. (It doesn't chase down any dot-sourcing of other scripts from that file.)

  • #26931
    Profile photo of Bor

    I tested "NestedModules" in manifest and it did not work. Now I get it... Thank you very much Dave for the great explanation!

You must be logged in to reply to this topic.