Powershell DSC: Composite Resources with parameters not working

前端 未结 1 1066
遇见更好的自我
遇见更好的自我 2021-01-15 02:37

I\'m working on a DSC composite resource, but I can\'t seem to get it working. My code:

E:\\Dev\\DSCResources\\run.ps1:

Import-Modul         


        
相关标签:
1条回答
  • 2021-01-15 02:54

    After your update I could successfully reproduce your problem, after which I couldn't get my original configuration working again, making me believe I made some kind of error in my original test. In the following examples, I will use BaseConfig for config name and MyParameter for parameter name.

    In order to create a longer description with line-by-line instructions, I wrote a blog post on the subject: http://robertwesterlund.net/post/2014/03/12/creating-a-composite-dsc-configuration-with-parameters

    Parameters to a Composite Configuration which is an ordinary module

    When a Composite Configuration is created as an ordinary module (directly in the C:\Program Files\WindowsPowerShell\Modules\MyModuleName, for example), it seems like it behaves like an ordinary Cmdlet. This means, to pass parameters to the composite configuration I had to do:

    Import-DscResource -ModuleName BaseConfig 
    
    Node localhost 
    { 
        BaseConfig Common -MyParameter "My Parameter Value" 
        { 
        } 
    } 
    

    I must admit that I don't know if this would behave as expected for a DSC resource for other parts.

    A Composite Configuration which supports parameters

    The way I wanted to write the configuration was the following:

    Import-DscResource -Name BaseConfig 
    
    Node localhost 
    { 
        BaseConfig Common 
        { 
            MyParameter = "My Parameter Value" 
        } 
    } 
    

    (Notice that the Import-DscResource also differs.)

    To get this working, I had to make a dummy container module (which, of course, could contain implementation if necessary, but I only created an empty psm1 file and a psd1 file pointing to that psm1 file. After making the container module without implementation, I then made a DSC Resource module (located in the MyContainerModule\DSCResources\MyCompositeConfiguration folder) for the composite configuration. After this it worked just as expected. This is probably the correct way to create a composite configuration.

    0 讨论(0)
提交回复
热议问题