Search code examples
powershelldscpowershell-5.0

DSC Custom Resource Dependencies


In DSC how can I create a custom module (either PowerShell 5 DSC class or MOF + Script) and express that it requires/has a dependency on another DSC resource (like xBlah from PowerShell Gallery).

In chef, I can put such dependencies in my metadata.rb file to express inter-cookbook dependencies. Is there any way of expressing inter-resource dependencies in DSC?


Solution

  • You will need to implement DependsOn keyword in your custom resource. Then you can use this in your configuration to define dependencies. The general format is:

    DependsOn = "[DSC Resource type] Name of the block"
    

    You can even specify multiple dependencies as array as shown in the below example in a configuration:

    DependsOn = @(“[WindowsFeature]HyperV”,
                          “[File]VHDFolder”)
    

    Reference for usage: Configuring Dependencies in "Desired State Configuration" script in PowerShell

    Another more apt reference: DSC 201 – Custom Actions