Use DSC to Install Windows PowerShell DSC Resource Kit Bits


Summary: Learn how to use DSC to install Windows PowerShell Desired State Configuration Resource Kit bits.

Microsoft Scripting Guy, Ed Wilson, is here. Fall has definitely arrived here in Charlotte, North Carolina in the southern portion of the United States. The mornings are cool, the evenings are clear and crisp, and the midday sun does not warm things beyond a reasonable amount. People are out and about—people who I did not even know existed in our neighborhood.

It is a friendly time of the year, and it is one of the main reasons we put up with the oppressive heat and humidity of southern summers. The Scripting Wife and I are thinking about heading to the Renaissance Festival over the weekend. I don’t know for sure yet—but it might be fun. We went to one several years ago, but it is probably about time to go again. After all, how often does one get to see jousting tournaments?

Speaking of jousting…

Today’s post is easy. I am going to install the Windows PowerShell Desired State Configuration (DSC) Resource Kit bits on several servers, and I am going to use DSC to do it. This is because I will not need to have access to the additional DSC resource providers that the Resource Kit provides to accomplish the task.

Why? Well, because Windows PowerShell 4.0 includes DSC and over a dozen resource providers by default. Those I need for today's task are already in the box. And as they may say at the Renaissance Festival, “That doth sweetly ringeth upon mine ears.” They might say that if they know how to use Windows PowerShell to help with their configuration needs.

DSC providers to the rescue

I am going to use two standard DSC resource providers: the File provider and the Archive provider. What is cool about this is that I can use the File provider to copy a .zip file to a specific location on my remote servers. I can then use the Archive provider to unzip the files and expand them to a specific location.

In this case, my file is the ResKit.zip file I copied yesterday from the Script Center Repository, and my destination location is the Program Files\Windows PowerShell\Modules folder that is recommended in the Readme file. I begin my DSC configuration script on my client workstation with the following:

#Requires -version 4.0

Configuration ReskitUnzip

{

 Param ($modulePath = ($env:PSModulePath -split ';' |

    ?  {$_ -match 'Program Files'}),

    $Server = @('S1','S2','DC1'))

Obviously, it requires Windows PowerShell 4.0, so there is no reason not to add this #Requires command to my script. I use the Configuration keyword and specify a name for my configuration. I am calling it ResKitUnzip for obvious reasons. I now specify parameters, like I would in a regular Windows PowerShell function. I find my path for the module folder by splitting the PSModulePath environmental variable and looking for a match with Program Files. When I have that, I assign an array of server names to the $server variable. Cool.

Using providers to do things

Now I need to specify which node I want to do things to. This is easy. I will assign my array of server names to the node parameter. I then use the File provider to specify that I want to copy my source files from my DC1 share location.

The destination path will become a location on each local server, and it does not need to exist prior to this operation. This is, in fact, what the Ensure command does—it makes certain the folder exists, and then it will copy all of the files to the location. I use the type of Directory because it will create a directory and copy all of my files there. Here is this portion of the configuration:

node $Server

    {

      File ScriptFiles

      {

        SourcePath = "\\dc1\Share\DSCResKit"

        DestinationPath = "C:\DSCResKit"

        Ensure = "present"

        Type = "Directory"

        Recurse = $true

      }

The Archive provider works the same way. I use the Archive provider keyword and specify a name for the operation. I specify that it depends on the previous operation (which I called ScriptFiles), and I specify my destination. Again, this is the destination that is relative to each of my local servers. I then ensure that it is present. That is it. This automatically extracts the zipped files and places them in the location I specified. Here is this portion of the operation:

      Archive ZippedModule

      {

        DependsOn = "[File]ScriptFiles"

        Path = "C:\DSCResKit\Reskit.zip"

        Destination = $modulePath

        Ensure = "Present"

      }

Now I call the configuration and specify my output for the configuration. This output is created locally to the computer from which I run my configuration script. Here is the command:

ReskitUnZip -output C:\serverConfig

Inside this folder, there are three .mof files that will be used to configure the three remote servers. Here is a view of that folder:

Image of menu

The last thing I do is start the configuration with this command:

Start-DscConfiguration -Path C:\serverConfig -JobName ServerConfig -Verbose

The output tells me how long it takes to do the configuration, in addition to the .mof files that are created and status about them. Here is the output:

Image of command output

The complete configuration script is shown here:

# Script: DSCResKitUnzip.ps1

#Requires -version 4.0

Configuration ReskitUnzip

{

 Param ($modulePath = ($env:PSModulePath -split ';' |

    ?  {$_ -match 'Program Files'}),

    $Server = @('S1','S2','DC1'))

    node $Server

    {

      File ScriptFiles

      {

        SourcePath = "\\dc1\Share\DSCResKit"

        DestinationPath = "C:\DSCResKit"

        Ensure = "present"

        Type = "Directory"

        Recurse = $true

      }

      Archive ZippedModule

      {

        DependsOn = "[File]ScriptFiles"

        Path = "C:\DSCResKit\Reskit.zip"

        Destination = $modulePath

        Ensure = "Present"

      }

    }

}

 

ReskitUnZip -output C:\serverConfig

Start-DscConfiguration -Path C:\serverConfig -JobName ServerConfig -Verbose

That is all there is to using DSC to install Windows PowerShell DSC Resource Kit bits. DSC Resource Kit Week will continue tomorrow when I will talk about more cool providers.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Comments (2)

  1. Another great tip. Thanks

  2. Cool piece number 2 with DSC. You can use the Azure Cmdlets to spin up a VM and use DSC to define it as well!

    Pretty sweet stuff too 🙂

    Sean

Skip to main content