Scripting Shared Nothing Live Migration
UPDATE: 16th September 2016 – Link to download fixed.
I was working with a customer recently to replace their existing Windows Server 2012 Hyper-V clusters and System Center 2012 SP1 Virtual Machine Manager (VMM) installation with new Windows Server 2012 Hyper-V clusters and System Center 2012 R2 Virtual Machine Manager installation.
The customer was concerned about downtime for moving their Virtual Machines (VMs) from their existing clusters to the new ones.
We looked at the option of using Shared Nothing Live Migration (SNLM) to move VMs between the clusters which whilst an option wasn’t entirely realistic due to having in excess of 250 VMs and the names of the Logical Switches were different so each VM took some time to manually process, and being a manual repetitive task is prone to errors. The customer thought they’d have to go through migrating roles, moving CSVs and taking down VMs etc. Whilst that doesn’t sound too bad I wanted to offer a better option.
So looking at the options in PowerShell it was obvious that Move-VM was the cmdlet I wanted to use. Looking at the parameters I found -CompatibilityReport which “Specifies a compatibility report which includes any adjustments required for the move.” my first thought was where do I get one of those from?
After a bit of digging on the internet I discovered Compare-VM which creates a Microsoft.Virtualization.Powershell.CompatibilityReport.
The Compatibility Report fundamentally contains information on what would happen if, in this case, wanted to move a VM from one host to another.
Compare-VM <VMName> -DestinationHost <DestinationServer> -DestinationStoragePath <DestinationStoragePath> -IncludeStorage
gave me a Compatibility Report with some incompatibilities listed… Again after some digging I determined what these incompatibilities meant and how to resolve them.
I could then run a Compare-VM -CompatibilityReport <VMReport> which essentially says, “if I did this to the VM would it work now?” As long as you get no incompatibilities all is good!
Once that completed we could use the Move-VM –CompatibilityReport <VMReport> function to move a VM from one host to another…
Now whilst all these Compare-VMs are underway the source VM is quite happy existing and running as normal.
So where is this going? After discussions with the customer I expanded the PowerShell script to cope with multiple VMs, check for Pass Through Disks, remove VMs from clusters, etc.
The basics of the script are that it requires several parameters:
- SourceCluster – where are the VMs to move?
- DestinationServer – where do you want to move the VMs to? (optional, if this isn’t specified then a random member of the destination cluster is chosen for each VM to be moved)
- DestinationCluster – what cluster do you want to move the VMs to?
- SwitchToConnectTo – what is the name of the Virtual Switch to use on the destination server/cluster? For example if you VM/VMs are connected to a virutal switch called LogSwitch1 but your new cluster uses a virtual switch named LogicalSwitch1 you would specifiy LogicalSwitch1 for this parameter.
- DestinationStoragePath – where do you want to put the VM’s storage on the destination cluster?
- VMsToMove – this is a list of the VMs to be moved
- LogPath – the path to a file you want to log the progress of the script to <optional>
Whilst this script may seem a little limited it managed to save the customer a great deal of time in migrating their VMs from their old Hyper-V clusters to their new ones. It can be extended to put in different Storage Paths for differenet VMs, different Virtual Switches etc.
Posted on 21 March, 2014, in Hyper-V, Microsoft, PowerShell, System Center 2012 R2, Windows Server 2012, Windows Server 2012 R2 and tagged Hyper-V, Microsoft, System Center 2012 R2, Windows PowerShell. Bookmark the permalink. 2 Comments.