For several years I have been speaking and writing about desktop deployment to standardize your client system environment. What about your servers? What about your hypervisors?
A couple of years ago VMware introduced Host Profiles into vCenter Server which allow you to take all of the settings from one host and then apply them to all of your other hosts. Nice… but unfortunately it is a feature only of the Enterprise Plus SKU of the product.
Microsoft has similar functionality with System Center 2012 R2, which is a real godsend for larger organizations. But what about the smaller companies? What about companies that have not completely implemented the whole System Center suite of tools? Are they doomed to having multiple hypervisor configurations? No… that’s what PowerShell is for!
Okay, PowerShell is for a lot of things; in fact it is for just about everything, depending on how well you want to use it. However with the help of my friend and fellow Microsoft MVP Sean Kearney I have put together a list of cmdlets that will do the job for you.
Firstly we should recognize that there are infinitely more settings to configure in VMware vSphere than there are in Microsoft’s Hyper-V; hundreds of settings, any of which can prevent critical functionality from performing properly. There are certainly issues that need to be properly configured in Hyper-V, but not nearly as many. With that being said, it is still important to standardize your Hyper-V hosts, if for no other reason than to simplify management, but also to ensure failover readiness and more.
For the purpose of this article I am going to assume a directory on all hosts called c:\Profile. You can really name the directory anything you like. In fact none of the file names have to be what I call them, as long as you remember what you use.
In PowerShell there is a simple cmdlet: Get-VMHost |fl. This will show you all of the host settings. The fl gets the full list, instead of the basic information.
If you are simply trying to collect the host settings for the purpose of documentation, you can export this information to a .csv (comma separated value) file that can be read in a text editor or, more importantly, in Microsoft Office Excel. That cmdlet would be Get-VMHost |Export-CSV c:\Profile\HostSettings.csv.
While this is helpful for documentation purposes, in order to actually work with the information we are going to export it to a .xml (Extended Markup Language) file. It will be harder for us to read, but easier for the computer to work with. The cmdlet to do that is Get-VMHost |Export-CLIXML c:\Profile\HostSettings.xml.
Now that we have collected the information, we can start applying the information to other hosts. The corollary to any Get- cmdlet in PowerShell is a Set- cmdlet. However the .xml file has some information in it that we would not want to apply to each host – hostname, for example. So although we could theoretically apply each setting by hand (set-VMHost <parameter>) I have taken the liberty to write a script that would apply all of the information for you, based on the file we collected earlier:
Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath
Set-VMHost –VirtualMachinePath $info.VirtualMachinePath
Set-VMHost –MacAddressMinimum $info.MacAddressMinimum
Set-VMHost –MacAddressMaximum $info.MacAddressMaximum
Set-VMHost –MaximumStorageMigrations $info.MaximumStorageMigrations
Set-VMHost -UseAnyNetworkForMigration $info.UseAnyNetworkForMigration
Set-VMHost -FibreChannelWwnn $info.FibreChannelWwnn
Set-VMHost -FibreChannelWwpnMaximum $info.FibreChannelWwpnMaximum
Set-VMHost -FibreChannelWwpnMinimum $info.FibreChannelWwpnMinimum
Set-VMHost -ResourceMeteringSaveInterval $info.ResourceMeteringSaveInterval
Set-VMHost -NumaSpanningEnabled $info.NumaSpanningEnabled
Set-VMHost -EnableEnhancedSessionMode $info.EnableEnhancedSessionMode
Let’s look at the format of this script.
1) $info=Import-CLIXML C:\Profile\HostSettings.xml
What we are doing here is importing the .xml file that we created into a variable called $info. Each piece of information in the XML file will be called using that variable.
Next let’s look at one of the Set-VMHost lines:
2) Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath
What we are doing here is taking one of the parameters – the default directory for new virtual hard disks – and setting it with the VirtualHardDiskPath parameter from the .xml file… because we imported that file into $info, that sub-variable is expressed as $info.VirtualHardDiskPath. We will repeat that for each parameter.
So essentially for this script we are running the same cmdlet twelve times with different switches. Can we put them together into a single line? Sure… it would look like this:
Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath –VirtualMachinePath $info.VirtualMachinePath –MacAddressMinimum $info.MacAddressMinimum –MacAddressMaximum $info.MacAddressMaximum –MaximumStorageMigrations $info.MaximumStorageMigrations -UseAnyNetworkForMigration $info.UseAnyNetworkForMigration -FibreChannelWwnn $info.FibreChannelWwnn -FibreChannelWwpnMaximum $info.FibreChannelWwpnMaximum -FibreChannelWwpnMinimum $info.FibreChannelWwpnMinimum -ResourceMeteringSaveInterval $info.ResourceMeteringSaveInterval -NumaSpanningEnabled $info.NumaSpanningEnabled -EnableEnhancedSessionMode $info.EnableEnhancedSessionMode
It may look long and ugly, but the good news is you don’t have to type it out again… all you have to do is copy and paste it from this article!
Of course, you can clean it up a little… if you are not using virtual fibre channel, for example, you could remove all of the parameters that pertain to that. A lot of companies don’t care about the MAC addresses of their VMs and resource metering, so remove those. All of a sudden that line gets a lot smaller:
Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath –VirtualMachinePath $info.VirtualMachinePath –MaximumStorageMigrations $info.MaximumStorageMigrations -UseAnyNetworkForMigration $info.UseAnyNetworkForMigration -NumaSpanningEnabled $info.NumaSpanningEnabled -EnableEnhancedSessionMode $info.EnableEnhancedSessionMode
Because PowerShell is plain English, you can easily go through these scripts and customize it the way you like. No worries, have fun!
Of course, you may have noticed by now that we have not even touched on virtual networks here, and that is certainly an important component. What do we need for that? You need to read my next article!