The configuration keyword

A DSC configuration block starts with declaring the configuration keyword and a name for the configuration block. It follows PowerShell function name declaration rules, but otherwise, there are no requirements on what to name it.

Choose the name of the DSC configuration block carefully as it will not only be how you refer to what configuration is applied, but by default, it will also be the name of the output folder where the MOF files are placed after compilation. You can change the name and path using the OutputPath parameter. Technically, it does not have to be unique as the additional metadata written to the MOF file on compilation helps identify what exactly is deployed to target nodes, but it helps to be as descriptive as possible.

The DSC configuration block can be treated like a PowerShell function declaration in that it accepts parameter statements and contains code inside it. This is important to note, as this means you can control how the DSC configuration block behaves both by the parameter statements defined as well as the defining custom parameters.

There are two built-in parameters that are always present in any configuration block you define: the ConfigurationData and the OutputPath parameters. We just mentioned the OutputPath parameter. The ConfigurationData parameter allows you to specify the environmental data to your function, which we covered in the DSC automatic variables section. You can define custom parameters by adding a param statement to your configuration block:

Configuration InstallExampleSoftware
{
param(
$computer,
$ExampleSoftwareName,
$ExampleSoftwareProductId,
$ExampleSoftwarePath,
$ConfigFileContents)

Node $computer
{
WindowsFeature DotNet
{
Ensure = 'Present'
Name = 'NET-Framework-45-Core'
}

File ConfigFile
{
DestinationPath = "c:foo.txt"
Contents = $ConfigFileContents
}

Package InstallExampleSoftware
{
Ensure = "Present"
Name = $ExampleSoftwareName
ProductId = $ExampleSoftwareProductId
Path = $ExampleSoftwarePath
DependsOn = @('[WindowsFeature]DotNet')
}
}
}

You would execute the preceding configuration block as follows:

InstallExampleSoftware -computer "foo1" -ExampleSoftwareName 'FooSoftware' -ExampleSoftwareProductId '4909a5d0-b3c3-4a98-be90-a0dcee7c4eef' -ExampleSoftwarePath 'e:sourcefoosoftware.msi' -ConfigFileContents (Get-Content "Config.xml")

For the most part, you will likely prefer to not use custom parameter statements and rely on the more powerful $AllNodes or $Node variables instead, as they provide superior flexibility and do not require you to provide them inline. We will cover examples that prove this statement in the Defining a DSC configuration data file section later in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset