And here I thought this was an easy one.
Objective:
1) Move 100+ VMs from one Cluster to another
2) Change network the guest is using
3) Move needs to be fast
Prerequisites:
1) Ensure LUNs from old Cluster are visible from new Cluster
2) Ensure proper VLANs are available
3) Ensure Tools are running
Since vMotion is not an option, a shutdown and startup is required. I put together the following simple script to shutdown guest; wait until machine is not running and do a Move-VM and Start-VM.
Script:
$vms = Import-CSVC:\Scripts\PowerCLI\CSmoveInput.csv
foreach ($vm in $vms){
$VMdestination = Get-VMHost $vm.tVMhost
$Network = $vm.tVLAN
Get-VM -Name $vm.name | Get-NetworkAdapter | Set-NetworkAdapter -StartConnected:$true -Confirm:$false -NetworkName $Network
Shutdown-VMGuest -VM $vm.name -Confirm:$false
while (Get-VMGuest $vm.name | where{$_.State -eq "Running"})
{
echo "Machine is Still Running"
Sleep -Seconds 3
}
Write-Host $vm.name is off
Move-VM -vm $vm.name -Destination$VMdestination
Start-VM -vm $vm.name
}
Most of the time it works fine but too often I get "The operation is not allowed in the current state."
Is there a better way to ensure the VM is OFF?
Any help is greatly appreciated!
Robert