What Can I Configure Using Desired State Configuration?

As we continue to investigate Desired State Configuration, you may be wondering what you can do with DSC. In short, quite a lot. But the true potential lies in the ability to extend the reach of the tool. Today I’ll go over what you can configure with Desired State Configuration, the resources offered, and we’ll combine these to create a configuration which we can then apply to our nodes to put them in a desired state.

Desired State Configuration and Resource Providers

With the initial release of DSC, Microsoft have included in the package a number of Resource Providers, which define some of the settings which can be managed by the system. Each Resource Provider has a specific purpose, with 12 of these available to be used in our configurations. One of these, the Script provider, allows us to extend the reach of our configuration even further through some simple PowerShell commands:

Resource Name

Description

Log

Resource to enable easy posting of messages to Logs

Environment

Manage environmental variables on the system

Registry

Manipulate the local registry settings of the node

File

Manipulates files and directories

Archive

Unpacks an archive file (.zip) to a specified location.

Package

Install and Manage packages, including .MSI and .EXE

Service

Change the configuration of services

Process

Manage processes on the node

WindowsFeature

Manage Windows Roles and Features

Group

Manage and Update Local Computer Groups

User

Manage and Update Local Computer User Accounts

Script

Execute a Windows PowerShell script block – extending the abilities

Using a Provider

To get a better understanding of what each of the providers enables us to configure, we will take a closer look at a simple example for each of the different providers, which we can then leverage to help us generate our initial configuration.

Log

PowerShell

1

2

3

4

5

LogSampleMessage

{

# Write a message to Microsoft-Windows-Desired State Configuration/Analytic log

Service

# Ensure the Remote Desktop Service is Set to Automatic and is Running

Ensure=Present

Name="TermService"

StartupType="Automatic"

State="Running"

}

WindowsFeature

PowerShell

1

2

3

4

5

6

WindowsFeaturesnmp

{

# Ensure the Windows Feature for SNMP is Installed

Ensure="Present"

Name='SNMP-Service'

}

Group

PowerShell

1

2

3

4

5

6

7

GroupGroupExample

{

# Ensure that our user is a member of the group

Ensure="Present"

Name="Administrators"

MemberToInclude="Domain\MyUser"

}

User

PowerShell

1

2

3

4

5

6

UserUserExample

{

Ensure="Present"# To ensure the user account does not exist, set Ensure to "Absent"

UserName="SomeName"

Password=$passwordCred

}

Script

PowerShell

1

2

3

4

5

6

7

ScriptInstallZoomIt

{

DependsOn='[Archive]ZoomItArch'

SetScript={&c:\Install\ZoomIT\ZoomIT.exe}

TestScript={Test-Path"C:\Program Files (x86)\ZoomIT\ZoomIT.exe"}

GetScript={return@{Name="C:\Program Files (x86)\ZoomIT\ZoomIT.exe"}}

}

Combining the Resources

With a good idea of what we can do, and with the resources offered for our use, all we need to do now is combine these to create a configuration that we can then apply to our nodes and put them in a desired state.

As a quick and simple example:

PowerShell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

ConfigurationMyQuickSample

{

NodeLocalHost

{

WindowsFeaturesnmp

{

# Ensure the Windows Feature for SNMP is Installed

Ensure="Present"

Name='SNMP-Service'

}

PackageDellOMSABinaries{

# Ensure that the Dell OpenManage Software is Installed to the Server

Ensure="Present"

Path="\\Server\Share\DellOSMA.msi"

Name="Dell OpenManage Systems Management Software (64-Bit)"

ProductID="12345678-1234-12345678-12345678"

Arguments="ADDLOCAL=ALL"

}

}

}

There you have it! Join me for the next installment in this series, in which I show you how to create a Desired State Configuration.

MEMBER LOGIN:

BECOME A PETRI MEMBER:

About the Contributor

Damian is an Infrastructure Architect currently focused on cloud technologies in the converged data-center, with perspective on service management automation for repeatable processes in “Dev/Ops” scenarios, leveraging Software Defined Networks (SDN) and Microsoft’s Azure Pack.

He has a keen interest in cloud computing from both a business strategy and technical viewpoint and has presented sessions on building and managing private/hybrid clouds at a number of industry events. Damian authored the cloud chapters on two books – Microsoft Private Cloud Computing (Sybex), and Windows Server 2012 Hyper-V Installation and Configuration Guide (Sybex) — and is active in many Microsoft programs, is a Microsoft MVP, and has published a number of white papers, technical articles and webinars.