Automation

 View Only
  • 1.  Move VMs to resource pools on another cluster

    Posted 15 days ago
    We are going to cancel the cluster with resource pools and we need to move all VMs (some of them are on, some off) to another cluster with same structure of resource pools (RP). Storages on both clusters are same.
    Is possible to do this with powershell ?
    Example:
    Cluster1
       Team1 (RP)
          VM5
         name1 (RP)
            VM1  (on)
            VM2  (off)
          name2 (RP)
             VM3 (on)
             VM4  (off)
    we need move to:
    Cluster2
       Team1 (RP)
          name1 (RP)
          name2 (RP)


  • 2.  RE: Move VMs to resource pools on another cluster

    Posted 15 days ago
    Edited by LucD 15 days ago

    You can use the Move-VM cmdlet.
    Note that the latest PowerCLI version produces an error ("A specified parameter was not correct: RelocateSpec"), but the move is executed.

    Get-VM -Name MyVM | 
    Move-VM -Destination (Get-CLuster -Name tgtCluster | Get-ResourcePool -Name tgtRP)



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 3.  RE: Move VMs to resource pools on another cluster

    Posted 15 days ago

    Is not possible make more automate ? There are about 80 resource pools and hundreds of VMs.

    Use Move-Inventory is not suitable for this ? 




  • 4.  RE: Move VMs to resource pools on another cluster

    Posted 15 days ago

    Since you are moving to another cluster there is vMotion and svMotion involved, that needs to be done with Move-VM afaik.



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 5.  RE: Move VMs to resource pools on another cluster

    Posted 15 days ago

    I need something like this: https://www.linkedin.com/pulse/migrate-your-vcenter-powercli-jesse-buschhaus/ but only for resource pools. Folders and vcenter will not change.




  • 6.  RE: Move VMs to resource pools on another cluster

    Posted 15 days ago

    That is for a complete vCenter to vCenter migration.
    Since that script is migrating the Datastores there is no vMotion/svMotion required, only a registration of the VMs in the new vCenter.
    That is completely different from what you described in your original question.



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 7.  RE: Move VMs to resource pools on another cluster

    Posted 15 days ago

    My idea was something like code bellow. Will this work ?

    $sourceCluster = Get-Cluster -Name "Cluster1"
    $destinationCluster = Get-Cluster -Name "DestinationCluster"
    
    # Get all resource pools in the source cluster
    $sourceResourcePools = Get-ResourcePool -Location $sourceCluster
    
    foreach ($sourceResourcePool in $sourceResourcePools) {
        # Get the corresponding resource pool in the destination cluster
        $destinationResourcePool = Get-ResourcePool -Location $destinationCluster | Where-Object { $_.Name -eq $sourceResourcePool.Name }
        
        if ($destinationResourcePool) {
            # Get all powered-on VMs in the source resource pool
            $vms = Get-VM -ResourcePool $sourceResourcePool | Where-Object { $_.PowerState -eq "PoweredOn" }
            
            # Move each powered-on VM to the corresponding resource pool in the destination cluster
            foreach ($vm in $vms) {
                Move-VM -VM $vm -Destination $destinationResourcePool
            }
        } else {
            Write-Host "Resource pool '$($sourceResourcePool.Name)' not found in the destination cluster."
        }
    }




  • 8.  RE: Move VMs to resource pools on another cluster

    Posted 15 days ago

    I'm afraid not since you are moving the VMs to another Cluster, which has different ESXi nodes and Datastores.
    You will have to include the include the Cluster/ESXi node and Datastore as well on the Move-VM



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------



  • 9.  RE: Move VMs to resource pools on another cluster

    Posted 14 days ago

    Datastores will be same, shared accross datacenter, so will not used storage vmotion .




  • 10.  RE: Move VMs to resource pools on another cluster

    Posted 14 days ago

    In that case, you could just register the VMs in the new cluster with New-VM and specify the correct ResourcePool on that cmdlet.
    Don't forget to unregister the VMs first (with Remove-VM but don't delete the VM)



    ------------------------------


    Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference


    ------------------------------