Using PowerShell Desired State Configuration to Unzip Files

A couple of months ago I wrote a blog about a “PowerShell Function to Unzip Files Using the .NET Framework 4.5 with Fallback to COM“. I’ve since discovered that the new Desired State Configuration (DSC) feature in PowerShell version 4 can unzip files. You probably wouldn’t use this feature just to unzip a single file to a single server, but it does open up some interesting possibilities.

This blog article is not meant to be an all inclusive tutorial on DSC, it’s only meant to give you a peek inside the built-in DSC Archive Resource capabilities.

First, define your DSC configuration to create your MOF (Managed Object Format) file:

Notice that by parameterizing the configuration, I’m able to use my parameters instead of having to rewrite the configuration each time:


Voila! MOF file created:


Since I defined the ComputerName parameter as mandatory, if I forget to specify that parameter I’ll be prompted for a value for it. I can also specify more than one value and create multiple MOF files for different nodes, all with a single command:


Now I’ll apply this configuration to Server01 to place it in the desired state:


The first time I ran this command, I thought there was a problem with the archive file due to the messages about files missing or not being a file. This is actually DSC checking the destination to see if the files already exist.

I removed one of the files and reapplied the state to confirm that the messages about files missing are indeed about the destination and not the source:


What I really like is that reapplying the state only extracted the one missing file and not the entire archive since all of the other files already existed.


1 Comment

  1. Mario

    Hi Mike that’s great post, I was trying to customize it for multiple zip files using wildcards in a Path property but without any success. Do you know how to use DSC Archive resources for multiple zip files?


Leave a Reply

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

%d bloggers like this: