PowerShell DSC Custom Resource Journey – Day 1

In several of most recent posts about DSC I have been messing around with Virtual Machine Manager (VMM) using injected Configurations. All this process has taught me is that the VMM interface is a pain in the ass and the way templates are used and created is an absolute joke. So, I decided to do something about it. My first thought was to use an Orchestrator workflow with the VMM Integration Pack to do it. It didn’t take me long to realize that because I have hardly ever used Orchestrator that going that route wasn’t the best idea. My next option. Using DSC to completely build and configure a VM from end to end. This will of course require me to build my own Custom Resources using VMM cmdlets to compliment the other resources that are currently available using the xHyper-V DSC Resource . Let’s get to work :).

First step, what can I do with the xHyper-V Resource? Running Get-DSCResource shows the following resources are part of the xHyper-V Resource:

Lets check these out one at time.

Well, that’s interesting. How is that any different from the File resource?

So the MSFT_XFileDirectory Resource is just a scaled down version of the File Resource. Which makes me wonder why does it even exist when it doesn’t do anything the File Resource can’t do. Unless I am missing something obvious I won’t be using this Resource. On to xVHD!

Alright, this looks useful (aside from the fact that it creates the disk as dynamic and not fixed, which we don’t ever do in our environment). We can name the disk, tell it where to live, ensure it is there (I can’t wait to test this), give it a generation and maximum size, and a parent path (not sure what that’s for).

Alright, so xVHDFile. At first glance I don’t know why you would use this and not the xVHD Resource. Sounds like a blog post by itself! Moving on.

All of this is pretty self-explanatory. The memory, like the hard disk, is set to dynamic by default and you can’t change it, so that’s another thing I am going to need to deal with here. The WaitForIP Property seems especially handy if you are using DHCP (like I am).

This Resource would be used for creating a brand new Virtual Switch. I will need this since I am going to be testing all this impending craziness on HyperV on my computer locally.

The things I am going to need to do (that I can think of right now):

  • Either modify the xHyper-V Resources to accept Fixed disk size and Fixed memory values or create my own.
  • Attach a CD-ROM Drive and mount an .ISO (I may just end up using a .VHD in VMM with nothing but an OS on it instead of trying to figure out how to install an OS, seems like a disaster waiting to happen)
  • I am going to need a VM Name and Generation (This seems to be already taken care of)
  • Create & Set NetworkAdapter settings
  • Set VM Availability to High
  • Figure out some logic for determining what host to put the VM on based on the ratings shown in the GUI
  • Figure out some logic for determining where to put the .VHDX files and VM Configuration File based on available storage (or let the user specify)
  • Set NetworkAdapter VM Network, VirtualSwitch & VLAN
  • Specify the OS of the VLAN

And I am sure there are going to be some other things that come up, but for right now this list is a good place to start!