PowerShell DSC Custom Resource Journey – Day 3

In my last post, I used my Configuration to create a Lab Switch.  The next thing I need to is to create a hard drive for my VM.  I want to do this by using an existing .VHDX I have copied over from my VMM library to my local computer.  This .VHDX has only an OS installed (Server 2012 R2) and nothing else configured.

I am also referencing this page on TechNet about the Hyper-V Resource in working through this. First, lets take a look at the xVHD Resource Properties.

Based on this information, this is what I add to my existing Configuration script. I add a File section to my Configuration to copy the blank .VHDX over because the xVHD Resource can’t handle that. I will be curious to see how this works because I know from previous testing that the Resource creates a Dynamic sized hard disk, and the one I am going to attempt to copy and attach to the VM is a fixed size disk. Time to break stuff!

Here is the File section. My VHD is in C:\Scripts\VHDs and I want to copy that folder and the VHD it contains to C:\Scripts\VMs\$VMName.

I quickly realize this isn’t going to work because I won’t be able to run this the way that I want to on my local machine. Reworking my Configuration this is what I come up with.

So let’s run this and see if it copies my VHD properly or if it blows up massively in my face.

This happened because I am running ISE as my domain admin account. I run the same command from the PowerShell Console and it sits on this screen for what seems like a long time. I look and C:\Scripts\VMs\DSCLocalTest exists and the .VHD has been copied over (the file size is showing properly, but who knows if it is really copied over or not, or if the file system is just displaying its ending value and the copy is actually happening and I just can’t see it).

And here is some more proof so people don’t think I am crazy 🙂
At this point, I have checked Twitter a couple of times, added in all those images, and the DSC Configuration is still stuck on the exact same screen. I decided to kill it and re-run it. Because, why not?

Well, that’s fun! “The data is invalid”. WTF? My very first thought is “PC Load Letter? What the fuck does that mean?”. Office Space reference there. If you haven’t seen that movie, you need to do immediately. Anyways, back to the issue at hand. I already have Force = $True, so I am not sure what else to do. I guess I will just delete the directory and try it again. And this is where things get interesting.

Oh really? And what process would that be??? Looking at Get-Process, I don’t see anything jumps out. I close my PowerShell Console and try again, no luck. I try to delete the file manually, and I get this handy error message.

Alrighty then.

I have no idea, what to do here, and I am feeling frisky, so I am just going to stop every single one of those and see what happens. After saving all of my work of course.
Astonishingly enough, my computer did not explode. It killed all of them, and then it spawned 4 new processes. I was also able to delete the folder. So lets run this again and I will just leave it and see what happens, because obviously it was still doing something behind the scenes.
And here is what it is doing! I think the actual copy is going to take a while :).
32.67 Minutes, to be precise 🙂

I think that’s enough fun for one day :). I will pick it up tomorrow by trying to create a VM from this Fixed VHD and see what happens 🙂