PowerShell Desired State Configuration (DSC) Journey – Day 17

Yesterday I created  vSwitch on Hyper-V to use as part of building some VMs in the very near future (like this week).  Today I am going to create a VHD to use to build the VM.

Running Get-DSCResource I see that there are 2 similarly named Resources xVHD and xVHDFile.  What is the different between the two?  I have no idea.  Let’s see if I can figure it out.

I think it’s pretty clear that xVHD is the Resource that I want to use, but what is xVHDFile for?  Looking on the TechNet page for the Hyper-V Resource in the example section it says this about the xVHDFile Resource: “Customize VHD by copying a folders/files to the VHD before a VM can be created. Example below shows copying unattended.xml before a VM can be created”.  OK then, that makes sense (I suppose).

Before I create my xVHD Configuration, I recommend that you check out the comment for this Resource by Aleksandar Nikolić where he points out that right now there isn’t a way to get a Generation 1 VM that uses a .VHDX disk.  I start to build the Configuration, using parameters for the Resource Properties (most of them anyways) and immediately wonder if this is going to create a Fixed or Dynamic disk.  I have a suspicion it is going to create a Dynamic Disk (which is what Hyper-V defaults to).  I will find out soon enough!

Here is my Configuration.

And it fails miserably with these errors.

Looking at my Configuration again, this is what I get for using Copy-Paste for my Parameter blocks :).  I changed my Parameter blocks for $FilePath, $Generation and $MaxSize from [String[]] to [String] and everything works as expected.

I then run the command below, and gets lots of fun output.

It doesn’t think it has a name.  That’s weird.  I am going to guess it’s because my syntax is wrong, because I always forgot how to do this properly when trying to use a parameter name in text like this.  Luckily for me the TechNet example has the proper way to do it so I don’t have to go look it up myself.  I change what I had before to this and try it again.

More fun output!

Couple of things here.  I made the size of my VHDx file in MB instead of Bytes, so I need to fix that.  But seriously, why does it need to be in Bytes?  Is anyone really going to need to configure the size of a .VHDx down to the Byte level?  Is their some underlying code in Hyper-V that it can’t convert or recognize this itself?  I also find it humorous that the Local Configuration Manager reports that the VHDx is now Present, and then it says that it failed to create the disk.  Looking in my $FilePath directory no VHDx file was created.  It also tells us that errors were logged to the DSC/OperationalLog so let’s check that out.  Pretty boring.  It’s the exact same stuff that is in the Verbose output.  Although that raises an interesting question, if I run it without -Verbose what gets output on the screen.  Let’s try it.  All the important stuff still gets logged.  Alright, I have changed my VHDx size from 51200 to 53687091200 which is 50GB in Bytes.  Which really seems silly when it’s typed out like that.  Round 3!

And like I was afraid of it doesn’t create  a Fixed disk type, it just creates a disk with a size of 4,096 KB.  I have a feeling I know how I could fix that but let’s not get carried away right now 🙂

After doing this I also realized that I need to create a folder for the VM and put the VHD in that folder, so I add this to my Configuration Script.

And it works and everything looks great.  Tomorrow I will create a VM (or 3 or 4) using my VM Switch and this VHD file and see what else I can break.