Custom DSC Resource - Process only specified properties

This topic contains 3 replies, has 2 voices, and was last updated by  Don Jones 6 months, 1 week ago.

  • Author
  • #79213

    Christos Polydorou


    I'm writing a custom DSC resource and I'm facing the below issue.

    The custom resource supports many settings like Name, MaxConnections and Path. When the TargetResource functions are created, each one has all the settings of the custom resource as parameters. Now, when a configuration is authored that contains only the Name and MaxConnections settings, I need to have a way to exclude Path from the checks.

    I tried $PSBoundParameters but it seems that all parameters are passed.



  • #79264

    Don Jones

    All parameters are indeed passed – that's fundamental to how DSC works. I don't know what you mean by "exclude Path from the checks" – which "checks" are you referring to?

    So long as you haven't declared parameters as Mandatory, DSC will be fine if you omit them. Your code's logic can worry about whether something should be there or not and throw an error as appropriate.

    • #79309

      Christos Polydorou

      Hi Don,

      Consider the following example. We have a custom DSC resource named MyResource and the following configuration:

      Configuration cfg
          MyResource mrs
              Name = "Foo"
              SourcePath = "C:\Temp"
              DestinationPath = "D:\Temp"

      When developing the custom resource, I would like to be able to know if the "DestinationPath" was specified and test/set/get it or not. Not just because it might be required or related to the other parameters.

      I did some tests with the $PSBoundParameters again and it seems that it can be used for this purpose.


  • #79315

    Don Jones

    Ah, yes. Your resource will get whatever parameters were specified, and you can definitely test to see which ones were sent along. You can also implement null value checks, for example, in case a parameter was specified but not given a legal value.

You must be logged in to reply to this topic.