PowerCLI

 View Only
  • 1.  Clonning VM between different vCenters (from onprem to AVS)

    Posted Aug 28, 2023 09:41 AM

    Hi. I know how MOVE vm between onprem and AVS by powercli. But during this operation source VM is removed from onprem. I need script to only clone VM and leave original VM on source.

    In GUI interface when we IMPORT VM to vcenter exist option to check this.

     

     

    $vm = "test-vm"
    $sourceVM = Get-VM -Name $vm -Server $sourcevCenter
    $networkAdapter = Get-NetworkAdapter -VM $vm
    $destinationDatastore = Get-Datastore 'vsanDatastore' -Server $destinationvCenter
    $destinationHost = Get-Cluster Cluster-1 -Server $destinationvCenter | Get-VMHost -state connected | Get-Random 
    # Extract data from destination
    $cloneFolder = "tests"
    $network = Get-VirtualNetwork azure-net-test
    
    New-VM -Name nc-sql-test-Clone -VM $sourceVM -Datastore $destinationDatastore -VMHost $destinationHost -server $destinationvCenter -NetworkName $network

     

     

    Depends what i use i have different errors:


    "New-VM: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided."

    or if im using:

     

     

    New-VM -Name test-Clone -VM $sourceVM -Datastore $destinationDatastore -VMHost $destinationHost -server $destinationvCenter

     

    error: Permission to perform this operation was denied. Required privileges: 'HostSystem-host-43148' : 'Host.Config.Network

     

    Please about some advice.



  • 2.  RE: Clonning VM between different vCenters (from onprem to AVS)

    Posted Aug 28, 2023 06:31 PM

    The NetworkName parameter is not in the CloneVM parameterset of the New-VM cmdlet.

    The permission error seems to indicate that you are trying to "create" a network/networj config on that target ESXi node.
    While your account with which you are connected doesn't have that privilege.
    Does the Portgroup  connected to the source VM, exist on the target ESXi node?

    You could test if cloning on the same ESXi node, where the clone source is located, works.



  • 3.  RE: Clonning VM between different vCenters (from onprem to AVS)

    Posted Sep 07, 2023 12:46 PM

    I will try use this script for clone on source. 

    And network on source VM not exist on destination.

    On destination exists only networks (segments) created by NSX-T. On source customer use only vSphere and portgroups for VLANs.

    Im selecting specific network by: 

     

    $network = Get-VirtualNetwork azure-net-test

     

     

    Im doing similar script for moving VM and is working:

     

    $vmLocation = get-vm $temporaryClone
    $vm = Get-VM $temporaryClone -Location $vmLocation.VMHost.Name
    $destination=Get-Cluster Cluster-2 | Get-VMHost -state connected | Get-Random
    $networkAdapter = Get-NetworkAdapter -VM $vm
    $destinationDatastore = Get-Datastore 'vsanDatastore (1)'
    $network = Get-VirtualNetwork azure-net-test
    Write-Host -ForegroundColor YELLOW -BackgroundColor DarkGreen $time "Starting cross vCenter vMotion to AVS"
    $vm | Move-VM -Destination $destination -NetworkAdapter $networkAdapter -Datastore $destinationDatastore -Network $network

     

    But in this scenario VM is removed from source what is not my goal. I need original VM have on source in case of rollback



  • 4.  RE: Clonning VM between different vCenters (from onprem to AVS)

    Posted Sep 07, 2023 01:04 PM

    That code is moving the VM instead of cloning it.