PowerShell DSC

The Desired State Configuration (DSC) is a management platform in a PowerShell that is used for development, configuration, and management of systems. PowerShell DSC was introduced in version 4.0. So, if you want to use it, you need a version 4.0 or above of PowerShell. It is available on Linux, Windows, and Nano Server.

It provides a collection of PowerShell language extensions, cmdlets, and a process called declarative scripting.

It mainly consists of three components:

  • Configurations
  • Resources
  • Local Configuration Manager (LCM)

DSC Configurations

DSC Configurations are the scripts of PowerShell, which define a special type of function. We use the keyword Configuration to define the configuration.

Syntax of DSC Configuration

The configuration script consists of the following parts:

  • The configuration block: It is the outermost block of the script. We can define it by using the keyword configuration and providing a name.
  • One or more node block: These blocks define those nodes which you are configuring.
  • One or more resource block: These are the blocks where the configuration sets the properties for those resources which are configuring.

Example: In this example, we can specify the name of the node by passing the parameter computerName when we compile the configuration.

Type the following command to get the output of above example:


DSC Resources

The resources of desired state configuration provide the building blocks for the DSC configuration. The following are the basic built-in configuration resources of the Desired State Configuration:

  • File: This resource is used to manage the files and folders on a node.
  • Archive: It is used to decompress an archive in the .zip format.
  • Registry: It manages the registry key of a node (except HKEY Users).
  • Script: It is used to execute several PS commands on a node.
  • User: This is used to manage a local user on a node.
  • Log: The log resource writes a message in the DSC event log.
  • Package: This resource installs or removing a package.
  • WindowsFeature: It adds or removes a feature on a node.
  • WindowsOptionalFeature: This resource adds or removes an optional feature.
  • WindowsProcess: This resource of DSC manages a Windows process.
  • Service: It is used to manage Windows services such as State, Startup Type.
  • Environment: It manages system environment variables.

DSC Local Configuration Manager (LCM)

It is an engine of Desired State Configuration. The Local Configuration Manager is responsible for enacting and parsing configurations which are sent to the node. It controls all the executions of the DSC configurations.