Automation

 View Only
  • 1.  Partial clone of virtual machine in VMware (via cmd New-VM)

    Posted Mar 25, 2022 02:58 PM

    Can you help me how to clone a VM, but I need to omit some disks (I need a script for regular cloning, I know that in the GUI there is an option via Customize VMs HW), I use this cmd in  PowerCli script:
    New-VM -VM $VM1 -Name "$VM1-Clone" -VMHost $ESXi -datastore $Datastore -Notes "Clone $Time1" -Location "Clone"



  • 2.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)

    Broadcom Employee
    Posted Mar 25, 2022 03:53 PM

    Thread reported so moderators know it should be moved to the area for PowerCLI.

     



  • 3.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)

    Posted Mar 25, 2022 04:09 PM

    If you want to use the New-VM cmdlet, you will have to use a Remove-Harddisk after the cloning completes.

    If you want to do it in one call (like the Web Client), you will have to use the API.



  • 4.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)

    Posted Mar 28, 2022 07:04 AM

    Thanks Luc,

    Does it remove as a postprocess? I don't have space on the target datastore to clone the whole VM and then delete the data disk.



  • 5.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)

    Posted Mar 28, 2022 07:59 AM

    Not 100% sure how that method is implemented, but it looks in my tests that the excluded disk is not copied.



  • 6.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)

    Posted Mar 29, 2022 02:17 PM

    Great Luc, it works OK, now I still have a request to modify the script to send a cloned VM to another ESXi



  • 7.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)

    Posted Mar 29, 2022 02:42 PM

    In the VMware.Vim.VirtualMachineRelocateSpec object is a Host property where you can enter the MoRef (ID) of the target ESXi node. 



  • 8.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)

    Posted Mar 29, 2022 03:02 PM


  • 9.  RE: Partial clone of virtual machine in VMware (via cmd New-VM)
    Best Answer

    Posted Mar 25, 2022 05:09 PM

    To use the API, you could do something like this


     wrote:

    Can you help me how to clone a VM, but I need to omit some disks (I need a script for regular cloning, I know that in the GUI there is an option via Customize VMs HW), I use this cmd in  PowerCli script:
    New-VM -VM $VM1 -Name "$VM1-Clone" -VMHost $ESXi -datastore $Datastore -Notes "Clone $Time1" -Location "Clone"