Hi,
Background,
I need to move alot of VM's from cluster A to cluster B. Cluster A and B have shared storage. Easy enough i thought and tried to use Move-VM.
Problem:
The VM's are located in Resourcepools. It looks like i can't do something like,
Move-VM -VM $VMs -Destination ClusterB -Destination ResourcePoolB
Parameters on Move-VM states "Specify a folder, host, cluster, or a resource pool where you want to move the virtual machines."
From that i understand that what im trying to do is not doable, i have to pick on of them.
Anyone have a suggestion?
You can't have two Destination parameters.
You pick the target resourcepool, which implicitly contains the selected cluster.
Something like this
Move-VM -VM $vms -Destination $rp
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah of course! I knew i was missing something obvious.
Thanks alot for the fast reply!
Seems like that din't work either
error:
Destination is a Resource Pool owned by a Cluster, but the VM you are trying to move is not in that Cluster. Please select for destination
a Host in that Cluster or a Resource Pool owned by a standalone Host.
Which vSphere and PowerCLI versions are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is that PowerCLI 6.5R1 (the one from the MSI file) or 6.5.1 (the one from the PSGallery)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
As an alternative, does this work?
$rp = Get-ResourcePool -Name ResourcePoolB -Location $cluster
$esx = Get-VMHost -Location $cluster | Get-Random
Move-VM -VM $vms -Destination $esx |
Move-VM -Destination $rp
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks alot for all input!
Move-VM -VM $vms -Destination $esx |
Move-VM -Destination $rp
Doing like you did Move-VM get an parsing error so i just removed | and did like this
Move-VM -VM $VMs[0..1] -Destination $ESX
Move-VM -VM $VMs[0..1] -Destination $rp
This works fine, to the root first then into the correct resourcepool at the destination cluster. Now i just have to figure out how to pace this since i dont want to que up 300 vMotions to the $esx since that will be the same host during the whole move.
You can use the RunAsync switch on the Move-VM cmdlet, but then you will have to keep track of the background tasks.
Especially since there are 2 Move-VM cmdlet you have to do, and they have to be in the correct sequence, and the 2nd one can't start before the 1st one has completed.
An alternative is to use PowerShell background job with the Start-Job cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I looked a bit at the RunAsync, looks like it can get a bit messy. I will take a look at Start-Job cmdlet.
Can i just use what i have and somehow refresh $esx = Get-VMHost -Location $DSTCluster | Get-Random after every move?
Move-VM to cluster
Move-VM to resourcepool
Get-VMHost -Location $DSTCluster | Get-Random
Maybe a Start-Sleep
This way a i can drain the cluster slow and steady and not end up with all VMs on one host. I have been looking around and havent found a good way to do as i describe above. As you all can tell by now im new to this so bear with me 🙂 Why couldent jsut the Move-VM command let ju move things to a new cluster/resourcepool instead of just one of them 🙂
Sure you can do that, and that is indeed a good approach to spread the load.
I'm not sure why you can't go for a cluster/resourcepool as the target.
That looks to be a PowerCLI thing, since the underlying API method seems to allow that.
Also note that there is a builtin max for the number of parallel vMotions you can perform.
Kind of a builtin safety valve
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Assuming that you have all the VMs you want to move in the $vms variable, you could do something like this.
Each run through the ForEach loop will pick a new random ESXi node in the cluster.
$rp = Get-ResourcePool -Name ResourcePoolB -Location $cluster
foreach ($vm in $vms) {
$esx = Get-VMHost -Location $cluster | Get-Random
Move-VM -VM $vm -Destination $esx |
Move-VM -Destination $rp
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Oops, my bad, I used $vms where I should have used $vm.
I updated the code.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference