I am trying to consolidate 2 clusters into one and decommision the old clusters. Here is a piece of my script, and I keep getting an error.
Connect-VIServer vcenter -Credential $ADCreds
$vms = Get-Cluster $Cluster1, $Cluster2 | Get-VM | Select Name
$vms | foreach-object {
Move-VM -VM $_.Name -Destination $Cluster3 -Confirm:$false -RunAsync
}
Disconnect-VIServer
Here is the error.
Move-VM : 8/22/2011 10:38:39 AM Move-VM You specified a Cluster as destination, but the VM you are trying to move is not in that Cluster. Please select for destination a Host in that Cluster.
At line:4 char:11
Could someone please shed some light on this issue. I know this can be done as I have seen basically the identical Move-VM command in this forum as a working command for other people. I know that I can do what I am trying to do because I have migrated a single VM through the client to the new cluster without any issue at all.
I can confirm that there is indeed a bug when using a cluster as the destination.
Can you try with the RelocateVM method ?
$vm = Get-VM MyVN $clus = Get-Cluster MyCluster $pool = Get-ResourcePool -Name Resources -Location $clus
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.pool = $pool.Extensiondata.MoRef $vm.ExtensionData.RelocateVM($spec,"defaultPriority")
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you try
Connect-VIServer vcenter -Credential $ADCreds
$vms = Get-VM -Location (Get-Cluster $Cluster1,$Cluster2)
$vms | foreach-object {
Move-VM -VM $_ -Destination $Cluster3 -Confirm:$false -RunAsync
}
Disconnect-VIServer
Btw which PowerCLI build are you using ?
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm not sure I've ever seen that cluster option work with Move-VM. You could simply just designate one host in the cluster to move to, or if you have alot to move you could alternate the host chosen on the fly.
Something like this would probably work assuming this is a multihost cluster.
$VMs | %{move-vm $_ -destination (($Cluster3 | get-vmhost | sort memoryusagemb)[0])}
Move-VM : 8/22/2011 11:29:14 AM Move-VM You specified a Cluster as destination, but the VM you are trying to move is not in that Cluster. Please sele
ct for destination a Host in that Cluster.
At line:2 char:11
+ Move-VM <<<< -VM $_ -Destination $Cluster3 -Confirm:$false -RunAsync
+ CategoryInfo : InvalidArgument: (ClusterName:ClusterImpl) [Move-VM], VimException
+ FullyQualifiedErrorId : Client20_VmHostServiceImpl_MoveVm_ClusterDestination,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM
I should mention that $Cluster1 and $Cluster2 are ESX 3.5 and $Cluster3 is ESX4. This is all running on vCenter Server 4.0
Do you have DRS enabled in $cluster3 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, DRS is enabled on all 3 clusters. There are about 120 VM's to move and don't want to have to specify a single host for this move, and since I can manually walk through the process without issues I figured I should be able to do it with PowerCLI.
PowerCLI is v. 4.1 Update 1
I can confirm that there is indeed a bug when using a cluster as the destination.
Can you try with the RelocateVM method ?
$vm = Get-VM MyVN $clus = Get-Cluster MyCluster $pool = Get-ResourcePool -Name Resources -Location $clus
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.pool = $pool.Extensiondata.MoRef $vm.ExtensionData.RelocateVM($spec,"defaultPriority")
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It appears that this will work. I have added in a loop to run this against a list of VM's as in the original code. I will let you know tomorrow how this works out for me tonight.