Share this page : facebooktwitterlinkedinmailfacebooktwitterlinkedinmail

Powershell 4.0 has a new feature, Desired State Configuration. DSC’s declarative syntax makes it possible for you to just tell the server how it should be configured without using the actual command for performing configuration steps.

DSC uses ” Pull” technology, servers can pull their configuration from a central server by using standard Web protocols. This technology eliminates the need to open additional firewall ports.

 

Practical applications

Following are some example scenarios where you can use built-in DSC resources to configure and manage a set of computers (also known as target nodes) in an automated way:

  • Enabling or disabling server roles and features
  • Managing registry settings
  • Managing files and directories
  • Starting, stopping, and managing processes and services
  • Managing groups and user accounts
  • Deploying new software
  • Managing environment variables
  • Running Windows PowerShell scripts
  • Fixing a configuration that has drifted away from the desired state
  • Discovering the actual configuration state on a given node
Key Concepts

DSC is a declarative platform used for configuration, deployment, and management of systems. It consists of three primary components:

  • Configurations are declarative PowerShell scripts which define and configure instances of resources. Upon running the configuration, DSC (and the resources being called by the configuration) will simply “make it so”, ensuring that the system exists in the state laid out by the configuration. DSC configurations are also idempotent: the Local Configuration Manager (LCM) will continue to ensure that machines are configured in whatever state the configuration declares.
  • Resources are the imperative building blocks of DSC which are written to model the various components of a sub-system and implement the control flow of their changing states. They reside within PowerShell modules and can be written to model something as generic as a file or a Windows process or as specific as an IIS server or a VM running in Azure.
  • The Local Configuration Manager (LCM) is the engine by which DSC facilitates the interaction between resources and configurations. The LCM regularly polls the system using the control flow implemented by resources to ensure that the state laid out by a Configuration is maintained. If the system is out of state, the LCM uses more logic inside of the resources to “make it so” according to the Configuration declaration.

Basic steps for using DSC:

  1. Create the script in the Powershell ISE
  2. Run the script to create configuration files called management object files(MOF) files.
  3. Enter the start-DscConfiguration cmdlet at a powershell prompt

Example:

Configuration MyDscConfiguration {

    Node "TEST-PC1" {
        WindowsFeature MyFeatureInstance {
            Ensure = "Present"
            Name =    "RSAT"
        }
        WindowsFeature My2ndFeatureInstance {
            Ensure = "Present"
            Name = "Bitlocker"
        }
    }
}

Save the script as a .ps1 file.

Configuration syntax

A configuration script consists of the following parts:

  • The Configuration block. This is the outermost script block. You define it by using the Configuration keyword and providing a name. In this case, the name of the configuration is “MyDscConfiguration”.
  • One or more Node blocks. These define the nodes (computers or VMs) that you are configuring. In the above configuration, there is one Node block that targets a computer named “TEST-PC1”.
  • One or more resource blocks. This is where the configuration sets the properties for the resources that it is configuring. In this case, there are two resource blocks, each of which call the “WindowsFeature” resource.

For more, see here: https://msdn.microsoft.com/en-us/powershell/dsc/overview