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:
1 2 3 4 5 |
PowerShell MSFT_xFileDirectory xHyper-V {DestinationPath, Attributes, Content, Ensure...} PowerShell xVHD xHyper-V {Name, Path, DependsOn, Ensure...} PowerShell xVhdFile xHyper-V {FileDirectory, VhdPath, DependsOn} PowerShell xVMHyperV xHyper-V {Name, VhdPath, DependsOn, Ensure...} PowerShell xVMSwitch xHyper-V {Name, Type, AllowManagementOS, DependsOn...} |
Lets check these out one at time.
1 2 3 4 5 6 7 8 9 10 11 12 |
PS C:\scripts> Get-DSCResource -Name MSFT_xFileDirectory | Select-Object -ExpandProperty Properties Name PropertyType IsMandatory Values ---- ------------ ----------- ------ DestinationPath [string] True {} Attributes [string[]] False {Archive, Hidden, ReadOnly, System} Content [string] False {} Ensure [string] False {Absent, Present} Force [bool] False {} Recurse [bool] False {} SourcePath [string] False {} Type [string] False {Directory, File} |
Well, that’s interesting. How is that any different from the File resource?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
PS C:\scripts> Get-DscResource -Name File | Select-Object -ExpandProperty Properties Name PropertyType IsMandatory Values ---- ------------ ----------- ------ DestinationPath [string] True {} Attributes [string[]] False {Archive, Hidden, ReadOnly, System} Checksum [string] False {CreatedDate, ModifiedDate, SHA-1, SHA-256...} Contents [string] False {} Credential [PSCredential] False {} DependsOn [string[]] False {} Ensure [string] False {Absent, Present} Force [bool] False {} MatchSource [bool] False {} Recurse [bool] False {} SourcePath [string] False {} Type [string] False {Directory, File} |
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!
1 2 3 4 5 6 7 8 9 10 11 |
PS C:\scripts> Get-DscResource -Name xVHD | Select-Object -ExpandProperty Properties Name PropertyType IsMandatory Values ---- ------------ ----------- ------ Name [string] True {} Path [string] True {} DependsOn [string[]] False {} Ensure [string] False {Absent, Present} Generation [string] False {Vhd, Vhdx} MaximumSizeBytes [UInt64] False {} ParentPath [string] False {} |
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).
1 2 3 4 5 6 7 |
PS C:\scripts> Get-DSCResource -Name xVHDFile | Select-Object -ExpandProperty Properties Name PropertyType IsMandatory Values ---- ------------ ----------- ------ FileDirectory [CimInstance[]] True {} VhdPath [string] True {} DependsOn [string[]] False {} |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
PS C:\scripts> Get-DSCResource -Name xVMHyperV | Select-Object -ExpandProperty Properties Name PropertyType IsMandatory Values ---- ------------ ----------- ------ Name [string] True {} VhdPath [string] True {} DependsOn [string[]] False {} Ensure [string] False {Absent, Present} Generation [string] False {Vhd, Vhdx} MACAddress [string] False {} MaximumMemory [UInt64] False {} MinimumMemory [UInt64] False {} Path [string] False {} ProcessorCount [UInt32] False {} RestartIfNeeded [bool] False {} StartupMemory [UInt64] False {} State [string] False {Off, Paused, Running} SwitchName [string] False {} WaitForIP [bool] False {} |
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).
1 2 3 4 5 6 7 8 9 10 |
PS C:\scripts> Get-DSCResource -Name xVMSwitch | Select-Object -ExpandProperty Properties Name PropertyType IsMandatory Values ---- ------------ ----------- ------ Name [string] True {} Type [string] True {External, Internal, Private} AllowManagementOS [bool] False {} DependsOn [string[]] False {} Ensure [string] False {Absent, Present} NetAdapterName [string] False {} |
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!