Pseudo-Splatting DSC Resources

Here’s a quick function to allow you something close to splatting with DSC resources:

Here’s why you may need it.

In DSC, quite often you need to specify a resource with some values like so:

But what if you have an hashtable readily available:

Or if you’re iterating through a list of  hashtable, and some don’t contain a value:

Well, until splatting is supported natively in DSC, you could use the following function as a way to support splatting in your configurations:

Be careful in which scope you’re executing this function, because DSC expect the scriptblock invoke in its own scope, not from another module.

But using this trick you can now do something like:

3 thoughts on “Pseudo-Splatting DSC Resources

  1. Thank you for this valuable idea! I tried it on a 1300 line DSC config and reduced it to under 200 lines. Much more readable with less duplication. One minor thing I noticed, after the config completed, was that the DependsOn values retrieved from Get-DscConfigurationStatus showed duplicate entries (i.e. the DependsOn value showed up twice). This didn’t affect the outcome as far as I can tell, and it may be my implementation of your suggestion that may have caused it so just wondering if you’ve observed it too. Thanks again well done.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s