DSC custom resource using Classes - Each class in separate file

Welcome Forums DSC (Desired State Configuration) DSC custom resource using Classes - Each class in separate file

This topic contains 2 replies, has 2 voices, and was last updated by

Bor
 
Participant
3 years, 6 months ago.

  • Author
    Posts
  • #26906
    Bor

    Participant
    Points: 0
    Rank: Member

    Hello,
    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

    Member
    Points: 0
    Rank: Member

    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
    Bor

    Participant
    Points: 0
    Rank: Member

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

The topic ‘DSC custom resource using Classes - Each class in separate file’ is closed to new replies.