Migrate VM´s in SCVMM 2012 from one cluster to a new
I have made a simple powershell function that can move VM´s from one cluster to another and also set the network configuration, this because the old cluster had one way of setup regarding the virtual machine network and the new another more flexible with promiscuous mode set on the HP nic team so i do not need to create one virtual switch for every vlan. The function also checks if the actual VM has snapshots before moving it. (the SCVMM calls it checkpoints, which is stupid to call it one thing in hyper-v and another in SCVMM!)
the powershell function looks like this:
function Migrate-VM { param ( [Parameter(Position=0,Mandatory=$true,HelpMessage="A virtual machine pleaze", ValueFromPipeline=$True)] $VM, [Parameter(Mandatory=$true)]$VMHost, $VMnic, $VMnetwork = "VMs", $Datastore = "C:\ClusterStorage\Volume1", [switch]$StartVM ) if( Get-SCVirtualMachine $VM | Get-SCVMCheckpoint) { $VM = Get-SCVirtualMachine $VM Write-Host " Please remove snapshots and do a shutdown of the VM:" + $VM.Name }else{ $JobGroupID = [guid]::NewGuid() $VMHost = Get-SCVMHost $VMHost $VMnic = Get-SCVirtualMachine $VM | Get-SCVirtualNetworkAdapter $LogicalNetwork = (Get-SCLogicalNetworkDefinition -VLanID $VMnic.VlanID).LogicalNetwork Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $VMnic -RunAsynchronously -VirtualNetwork $VMnetwork -LogicalNetwork $LogicalNetwork -VLanEnabled $true -VLanID $VMnic.VlanID -JobGroup $JobGroupID -EnableVMNetworkOptimization $false -EnableMACAddressSpoofing $false if($StartVM){ Move-SCVirtualMachine -VM $VM -VMHost $VMHost -HighlyAvailable $true -Path $Datastore -StartVMOnTarget -RunAsynchronously -UseLAN -JobGroup $JobGroupID }else { Move-SCVirtualMachine -VM $VM -VMHost $VMHost -HighlyAvailable $true -Path $Datastore -RunAsynchronously -UseLAN -JobGroup $JobGroupID } } }
And this screendump shows some different ways of running it,
Comments
[…] have made two blog posts a while ago about checking if a vm have snapshots before migrating it to another cluster and also a post about how you can extend the console with info on what virtual machines have […]