Desired State Configuration – A very basic intro

I’ve seen this topic before when reviewing the 70-410 exam books, though for that exam very little is mentioned or indeed required. So until now I’ve given it scant notice. However, having read more about it I can see it will continue to have a growing use in the years ahead, as my requirement to provision multiple standardised servers grows. DSC really looks like it can replace the need for storage-heavy VM templates and multiple GPOs and can quickly deploy standardised servers and maintain the initial settings in the event they are changed by well-meaning, but meddling System Administrators.

As I have only just dipped my toe into the DSC ocean, this post is really as much for my benefit as anyone eases (though I’m always glad to see you of course). It’s just a basic step-through to create a MOF file and apply that to the target. I don’t mention any of the underlying concepts and terminology because there’s a plethora of information out there on Technet and beyond.

Task: I need to ensure a new directory is created on my domain controller (CIV-DC1)

Create the Configuration file:

Configuration AccountingDir {

Import-DscResource –ModuleName ‘PSDesiredStateConfiguration’

Node CIV-DC1 {
#create a new directory in the C drive called accounting

File Accounting { 
Type = “Directory”
Ensure = “Present”
DestinationPath = “C:\Accounting” }

} #Node-complete

} #configuration-complete

#run this to create the MOF file
#the name of the configuration file
AccountingDir -OutputPath c:\temp

#run this to apply the MOF file to the target
Start-DscConfiguration -path C:\temp -Wait -Verbose -Force

NB: The image below will be used during the next section, I used the PowerShell ISE:

DSC-steps

NB: Please note line 3, when I did not have this I got the following error:

DSC-warning

Step 1: Load the Configuration Function Into Memory

Select the Configuration text and run this in ISE

Step 2: Generate the MOF file

Highlight the command (the name of the Configuration and specify a location where therMOF file will be stored) and run this in ISE, you should get the following output:

dsc-step2-output

Step 3: Apply the MOF settings to the target

Highlight the Start-DscConfiguration line, which includes the location of the MOF file (you don’t stipulate the actual MOF file) and run in ISE. The target for the MOF file is stipulated in the first lines of the MOF file so PowerShell and LCM know what the target is. If it is successfully applied you will see the following:

dsc-step3-output

Visually checking on CIV-DC1 shows the new directory:

dsc-results

You can also run a test to confirm if the settings in the MOF file are still active/applied on the target using the Test-DscConfiguration command:

DSC-testing

 

Disclaimer: provided “AS IS” with no warranties and confer no rights

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s