Defining a DSC configuration script file

Now that we're past the abstract concepts and the explanatory architecture, we can start addressing how to use DSC in real-world situations. Thus far in the book, we have been referring to the DSC configuration script files without really getting into the details of what they are. There isn't a specific file or file extension called a DSC configuration script file, it's the term used to describe the PowerShell script file that defines a special type of function: configuration.

You should be familiar with the general format of a DSC configuration block, as we have covered a few examples so far. Here is a simple one we will use as we move through the chapter. We will expand it to perform more advanced configurations and update it to allow multiple target nodes and use external configuration data:

Configuration InstallExampleSoftware
{
Node "localhost"
{
WindowsFeature DotNet
{
Ensure = 'Present'
Name = 'NET-Framework-45-Core'
}
}
}

While the preceding example is a DSC configuration block, it is not a DSC configuration script file. A DSC configuration block is the set of instructions used to compile the information to an MOF file. This file is a PowerShell script file (a file with the .ps1 or .psm1 extension) that is required to have at least one configuration block defined inside it. Inside the configuration block are the DSC resource import declarations and one or more node declarations. Inside the node declaration is one or more DSC resource blocks, where you define what state is expected on each node. So a DSC configuration block has the actual code, and the configuration script file is your mechanism to making MOF files.

The DSC configuration script files are allowed to have PowerShell code defined before or after the DSC configuration block, which means that a DSC configuration script could be inside a larger script or in a standalone script. We will see examples later on of using DSC configuration script files with and without additional code and the pros and cons of both approaches. To keep things simple, for the rest of the book, we will use the term DSC configuration script file to mean both a configuration block and a configuration script file.

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

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