Using A Single DSC Configuration for Multiple Servers

Ok so we’ve showed you some cool things. Building a DSC file, applying that configuration to a remote DMZ server.

But one thing you’ll probably have noticed. EACH and EVERYTIME I have done this I have typed in the name of the server in the Configuration. Seems a bit silly doesn’t it?

So unless I want to have a Configuration for each one of my servers. That doesn’t make too much sense. For example, if I want to spin up a file server, I’m pretty certain each of those servers will have the same features.

So under my present setup for two File servers called CONTOSO-FPS1 and CONTOSO-FPS2 I would have done something like this.

Configuration MySampleFileServer

{

Node CONTOSO-FPS1

{

WindowsFeature FileStorage

{

Ensure = "Present"

Name = "FileAndStorage-Services"

}

WindowsFeature PrinterSharing

{

Ensure = "Present"

Name = "Print-Services"

}

}

Node CONTOSO-FPS2

{

WindowsFeature FileStorage

{

Ensure = "Present"

Name = "FileAndStorage-Services"

}

WindowsFeature PrinterSharing

{

Ensure = "Present"

Name = "Print-Services"

}

}

}

This would absolutely work but I see a problem. If we CHANGE our standard File server configuration, we’ll have to edit EACH and EVERY Node. That’s not only time consuming but prone to errors.

However DSC works very much like any standard PowerShell function does, including the ability to pass parameters.

So what we CAN do is simply is inject a parameter at the top and replace the node name with a variable. So our ORIGINAL DSC would go from looking like this.

Configuration MySampleFileServer

{

Node CONTOSO-FPS

{

WindowsFeature FileStorage

{

Ensure = "Present"

Name = "FileAndStorage-Services"

}

WindowsFeature PrinterSharing

{

Ensure = "Present"

Name = "Print-Services"

}

}

}

To this by adding a Param() statement and giving our Node a PowerShell variable instead.