A new technology was released when Microsoft and the PowerShell team launched Windows Management Framework 4.0 and the latest incarnation of PowerShell.  

….and boy is its name a MOUTHFUL!

I am of course referring to DSC or “Desired State Configuration”.   A new feature brought forth that allows you to define the configuration of a server in a very simple fashion.

Let me step back though for a moment, let’s think about your standard server.   Once you have the operating system installed, what makes it unique from other servers?  Let’s pick some basics.

Name of Server

IP Address

Key roles and features required by the Server Application(s)

Normally you would navigate through the GUI to make the necessary changes.  If you were really good you’d write up a Vbscript or do something up with PowerShell to automate the changes.   Possibly you may even have used DISM.EXE or leveraged an Unattend.xml to smooth out this process.

All of these methods are still current and valid and hold their own special place but with DSC we have a more interesting option.    We can now literally create a simple and easy to read file which can define one or multiple servers for their configuration.

Anatomy of a DSC File

A basic DSC file follows a very simple format.   It will have

  • Configuration name

  • Node name (Your destination computer name)

  • DSCResource name(s)

Looking at a simplistic DSC file it would look like this.

Configuration NameOfConfiguration

{

              Node NameOfAComputerOrDevice

              {

                             DSCResource YourDescription

                             {

                             }

              }

}

 

Now although this is done within Windows PowerShell, the beautiful part is a DSC file really doesn’t look like much of a PowerShell script.    As you can see from the example below, here is an actual DSC configuration file.

Configuration MySampleFileServer

{

    Node CONTOSO-FPS

    {

        WindowsFeature FileStorage

        {

        Ensure = "Present"

        Name = "FileAndStorage-Services"

        }

        WindowsFeature PrinterSharing

        {

        Ensure = "Present"

        Name = "Print-Services"

        }

    }

}

 

So this DSC file has some really simple information.  The Configuration name is “MySampleFileServer”.  This could be anything but when you refer to this overall configuration its name is “MySampleFileServer”

This particular configuration is destined for a Server called “CONTOSO-FPS” which has some Features we’ll need.   The “FileandStorage-Services” and “Print-Services”.  As you can see we need to ensure each one is “Present”.

Not so bad.  I don’t see any real code, just a nice to read list.

Now how would I use that?  You place this into your PowerShell ISE (Integrated Scripting Environment) and execute it.   Once done at the PowerShell prompt type in the name of your Configuration and execute it, just like when you run a function.

MYSAMPLEFILESERVER

What will happen then is the file will create a folder called “MySampleFileServer” containing a file called “EOT-FPS.mof”

This file is your compiled DSC configuration.  You can open it up and read it.  It’s just a text file that looks like this.

/*

@TargetNode='CONTOSO-FPS'

@GeneratedBy=energizedtech

@GenerationDate=02/27/2014 18:53:082

@GenerationHost=MyDSCWorkstation

*/

 

instance of MSFT_RoleResource as $MSFT_RoleResource1ref

{

ResourceID = "[WindowsFeature]FileStorage";

 Ensure = "Present";

 SourceInfo = "C:\\ISO\\dsc-sample1.ps1::5::9::WindowsFeature";

 Name = "FileAndStorage-Services";

 ModuleName = "PSDesiredStateConfiguration";

 ModuleVersion = "1.0";

 

};

 

instance of MSFT_RoleResource as $MSFT_RoleResource2ref

{

ResourceID = "[WindowsFeature]PrinterSharing";

 Ensure = "Present";

 SourceInfo = "C:\\ISO\\dsc-sample1.ps1::10::9::WindowsFeature";

 Name = "Print-Services";

 ModuleName = "PSDesiredStateConfiguration";

 ModuleVersion = "1.0";

 

};

 

instance of OMI_ConfigurationDocument

{

 Version="1.0.0";

 Author="energizedtech";

 GenerationDate="02/27/2014 18:53:08";

 GenerationHost="MYDscWorkstation";

};

 

 

Now of course we can see why you want the DSC version.  It’s a LOT nicer on the eyes!  But as you can see the output is a .MOF file.  That’ right….. STANDARDS…. DSC now crosses into STANDARDS!

So how can we apply this to our server in question?  You’ll love this.   Just run the following Powershell Cmdlet with the created .MOF file.

START-DSCConfiguration C:\ISO\MySampleFileServer

In moments all of those settings on the destination server (presuming of course you are running PowerShell 4.0 on the remote system) will now be applied.

There’s a bit more to the Architecture.   This was only a simple Push configuration.  With DSC you can also have a Pull Configuration where Servers consistently check to make sure they are running in the “Desired State”.

Today we only showed you a simple setup.   A Basic file server.

But DSC can also trap for services, intended files, Registry settings and more.

Stick around, next time I’ll pop back in with a bit more for you to sink your teeth into.

Until then

Remember, the Power of Shell is in YOU

Sean
the Energized Tech
Windows PowerShell MVP
Honorary Scripting Guy