Composite DSC Resource not working

Welcome Forums DSC (Desired State Configuration) Composite DSC Resource not working

Viewing 9 reply threads
  • Author
    Posts
    • #16885
      Participant
      Topics: 10
      Replies: 26
      Points: 0
      Rank: Member

      Hi,

      Trying to use composite DSC ressource and have created the following:

      The .psd1 file got created by running this:

      However, the module does not show up:

      I have tried numerous time, different folder structure, trying in “C:\Program Files\WindowsPowerShell\DscService\Modules” folder also.

      And ofcourse, I also get an error when trying to Import-DSCResource CommonConfig in a .ps1 config file.

      Any thoughts?

      Best regards

      Stig

    • #16886
      Inactive
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      The folder name inside your module folder needs to be “DSCResources“, not “DSCResource”. Try changing that, and if it still doesn’t work, I’ll take a closer look at the code itself.

    • #16887
      Participant
      Topics: 10
      Replies: 26
      Points: 0
      Rank: Member

      Hi Dave, thank you very much for your fast reply.

      Nicely spotted with the missing “S”. Though, It did not help 🙁

      I also tried moving the .psd1 one step out from the DSCResources folder.

      From the DSC Books:

      – no DSCResources folder is mentioned?

      Best regards
      Stig

    • #16890
      Participant
      Topics: 5
      Replies: 39
      Points: 22
      Rank: Member

      I ran into this exact same issue with my Custom Resource, and the issue ended up being my folder structure was incorrect. I will just break down what I have now that works and you can check and see if it matches what you have.

    • #16891
      Inactive
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      Ah, right. The DSCResources folder is just for normal resources, not composite. For a composite resource, you put both the “schema.psm1” and psd1 files into the root folder of a module, and there doesn’t need to be a DSCResources folder at all.

      I’ll play around with this later and see if I can get it working. There may be a couple of errors in the DSC book that need to be ironed out. (One thing that jumps out at me right away is the use of positional parameters when calling Import-DscResource; this will give you an error. You need to type out Import-DscResource -ModuleName someModuleName ).

      Edit: On a side note, my composite resource would only show up in the output of Get-DscResource if I first imported the CommonConfig module. It wasn’t automatically detected the way other resources are.

    • #16900
      Participant
      Topics: 10
      Replies: 26
      Points: 0
      Rank: Member

      Thank you all for your reply. Unforturnally, changing the folder structure did not help, Jacob.



      @Dave
      > You are right about first importing the module in the PS prompt, then I can see it as an resource:

      When ‘compiling’ this configuration to a .mof file:

      No errors occours, but the .mof file does not contain anything from the CommonConfig resource.

      When I actually use the CommonConfig I get an error, first the configfile:

      The error:

      My CommonConfig psm1 file:

      Best regards,
      Stig

    • #16908
      Inactive
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      OK, ignore what I said earlier about being able to place the composite resources out in the root of a module folder. The only way I’ve been able to get this working reliably in testing is to place the composite resource into a subfolder of DSCResources, just like a normal resource. I wind up with the following folder structure, using your module and resource names:

      Directory: C:\Program Files\WindowsPowerShell\Modules\xCommonConfig

      Mode LastWriteTime Length Name
      —- ————- —— —-
      d—- 7/9/2014 9:50 AM DSCResources
      -a— 7/9/2014 9:50 AM 5248 xCommonConfig.psd1

      Directory: C:\Program Files\WindowsPowerShell\Modules\xCommonConfig\DSCResources

      Mode LastWriteTime Length Name
      —- ————- —— —-
      d—- 7/9/2014 10:16 AM CommonConfig

      Directory: C:\Program Files\WindowsPowerShell\Modules\xCommonConfig\DSCResources\CommonConfig

      Mode LastWriteTime Length Name
      —- ————- —— —-
      -a— 7/9/2014 9:50 AM 5236 CommonConfig.psd1
      -a— 7/9/2014 10:09 AM 164 CommonConfig.schema.psm1

      The good news is, Steven Murawski has already gone through this process, and some of the DSC-related scripts he’s written are already set up to create the proper folders and files. Check out https://github.com/PowerShellOrg/DSC/blob/master/Tooling/DscDevelopment/New-DscCompositeResource.ps1 . You can run the command as follows:

      This will take care of creating all the folders, PSD1 files, and a schema.psm1 file with an empty configuration. Then you just open up that file and paste in your current code for the CommonConfig configuration.

    • #16940
      Inactive
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      I’ve just uploaded some corrections to the DSC book’s section on Composite Resources. I copied and pasted all of the steps from the book, and ran them on a clean system to make sure they all worked properly.

    • #16944
      Participant
      Topics: 10
      Replies: 26
      Points: 0
      Rank: Member

      Thank you so much Dave! Everything is working now 🙂

      Used Steves script to create the module resource and there was no problem this time. The folder structure was wrong for me. Also thank you Jacob, you were right 🙂

      Best regards
      Stig Sörnsen

    • #16946
      Participant
      Topics: 5
      Replies: 39
      Points: 22
      Rank: Member

      Awesome, glad to hear it is working!

Viewing 9 reply threads
  • The topic ‘Composite DSC Resource not working’ is closed to new replies.