PowerShell DSC 101 Part 3: ConfigurationData (aka your NodeList)

Your ConfigurationData is essentially a list of nodes that you want a Configuration to apply to.

From Part 1:

ConfigurationData – This is, basically, a list of the nodes that PowerShell DSC will configure as per the Configuration.

 Here we need to present PowerShell DSC with a list of nodes in a way it understands.
Here is a very basic ConfigurationData collection:

Example:

@{
	AllNodes = @(
		@{
			NodeName	= "*"
			LogPath		= "C:\Logs"
		},

		@{
			NodeName		= "Win2016DC01"
			Role			= "PDC","DC","XPS"
		}
	)
}

Let us unpack this:

@{
	AllNodes = @(
		@{

Here we create a hashtable which does not have to be named, and then we create the AllNodes hashtable. AllNodes must be named thusly, this is so PowerShell DSC knows what you’re throwing at it.

		@{
			NodeName	= "*"
			LogPath		= "C:\Logs"
		},

Here we use a wild card to indicate that we want all nodes to have a LogPath of C:\Logs

		@{
			NodeName		= "Win2016DC01"
			Role			= "PDC","DC","XPS"
		}

This is where it gets interesting.
Here we can see that I specify a node by name, Win2016DC01, and I specify which roles it should have. As you can see, I can specify multiple roles on one line, separated by a comma.
This will then tell a Configuration which Features/Roles/Settings a node should have, and then create MOF files appropriately. This configuration is naturally very basic.

Unfortunately the Configuration I showed you in Part 1 would not be able to make use of a ConfigurationData file like the one I showed you here, so here is an appropriate Configuration:

Configuration MyDscConfiguration
{
	Node $AllNodes.Where{$_.Role -eq "XPS"}.NodeName
	{
		WindowsFeature XPS-Viewer
		{
			Ensure = "Absent"
			Name = "XPS-Viewer"
		}
	}
}

As you probably noticed, here we don’t specify a node by name, but instead specify that all Nodes in the ConfigurationData with a role of XPS will have the WindowsFeature XPS-Viewer removed.

This brings Part 3 to an end. I hope it has been helpful and informative.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s