Automate the installation of DSC Resource Kit Wave 9 resources with PowerShell Desired State Configuration

Last week, in my blog article titled “Creating Hyper-V VM’s with Desired State Configuration” I left off with a newly created Hyper-V VM named Test01 that was created with DSC and the specific IP address of that VM was added to my trusted host list. For more details on the current state of this test environment, see that previous blog article.

Today I’ll begin configuring the Test01 VM with DSC. This virtual machine will become the first Active Directory domain controller in my test environment. I want to statically assign the IP address information and I need to rename the server before I turn it into a domain controller. In order to accomplish those tasks, a few DSC resources need to be downloaded and added to the VM.

I would like to fully automate the entire build of my test environment with DSC and that task may seem overwhelming to some. Breaking it down into smaller steps makes the overall task seem much more manageable.

In this blog article, I’ll focus on automating the download of the DSC Resource Kit Wave 9 resources, extract all of those resources to a temporary folder, and copy only the ones I plan to use to the appropriate location. That way I’ll have all of the resources downloaded in case I need to use any of them for the other test VM’s that I plan to build.

I previously talked about using an initialization script in another blog article titled “Use a certificate with PowerShell DSC to add a server to Active Directory without hard coding a password” and I’ll take advantage of that technique here as well:

One thing that was definitely a challenge was using variables with the DSC script resource as shown in the following example. I used PowerShell here-strings to make them work.

The configuration is called which creates the MOF file:


Needless to say that there is a lot of “Verbose” output so I’ve omitted a large portion of it, but I think you’ll get the idea of what’s going on:


Applying the configuration a second time shows that everything is already done (note that all of the sets are skipped):


First, the DSC script resource is used to check to see if the DSC Resouce Kit Wave 9 zip file already exists in the “C:\tmp\DSC” folder which of course will return false if it doesn’t, it will also return false if the directory it’s looking for it in doesn’t exist either. If the “C:\tmp\DSC” folder doesn’t exist, it’s created, then the DSC Resouce Kit Wave 9 zip file is downloaded from the TechNet script repository.

Next the DSC archive resource is used to extract the contents of the zip file to the temporary folder which ends up being “C:\tmp\DSC\All Resources” due to the zip file creating the “All Resources” folder when its contents are extracted.

Then the DSC file resource is used to copy the DSC resources that I plan to use to further configure the Test01 VM to the appropriate location (“C:\Program Files\WindowsPowerShell\Modules”). This portion of the code is written using the ForEach method to eliminate redundant code in the actual DSC configuration.

Last but not least, dependencies are set using “DependsOn” to make sure the execution occurs in the proper sequence and to prevent the configuration from continuing if a prerequisite step fails that is required by a later step in the configuration.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: