Question

PowerShell Command Clone Virtual Machine

  • 5 November 2019
  • 5 replies
  • 3740 views

Userlevel 2
Badge +2

Could we get some more documentation on this command?

Clone-NTNXVirtualMachine

One of the required parameters is -SpecList

I would like some clarification on this parameter and how to use it. Is this an array of values? Am I linking to a csv or json file?

An example would be nice.

Using the UI, I currently clone a reference image to create vm’s and I would love to get a PS script to work to do the same. I can get it to work with the ACLI commands but PS is a bit more versatile and I believe I could get it to do more if I understood this command and specifically this parameter better.


5 replies

Userlevel 4
Badge +5

 

Cloning VM using PowerShell could be done to use Clone-NTNXVirtualMachine commandlet.
For example,

PS> spec = New-NTNXObject -Name VMCloneSpecDTO 
PS> spec.name = "cloneOne" 
PS> vm = get-ntnxvm | Where-Object { $_.vmName -eq "clone-base" } 
PS> Clone-NTNXVirtualMachine -Vmid $vm.vmId -SpecList $spec 

   +Create VMCloneSpecDTO and set new VM name to spec.name field.
   +Retrieve existing VM
   +Run Clone-NTNXVirtualMachine commandlet with vmid of the existing VM and spec object previously created.

 

So what exactly is New-NTNXObject?

 

The New-NTNXObject cmdlet to create a data transfer object (DTO) lists.

 

Hope this helps!

Hi,

In addition to above I need to set TCP/IP parameters to cloned VM (IP, Subnet mask, GW, DNS1, DNS2). What is the method/cmdlet/parameters should I use? May be another DTO object, I guess?

From Acropolis v1 API Reference .pdf  and from other forum(s) I understood that there are few DTO predefined Names (at least VMCloneSpecDTO, VMCloneDTO, VMCustomizationConfigDTO ). Where can I receive full description of DTOs / other useful info along with Nutanix Powershell cmdlets examples (not only minimal function description).

Hi 

 

were you able to get this working?

Hi,

I did it in my VMware environment with PowerCLI. Now I have to do this in Nutanix cluster.

 

Userlevel 4
Badge +5

Hello @ValeryV @Tshepo 

 

You can use cloud-init or Sysprep(based on OS) to provide the details while cloning a VM. 

Details regarding the cloud-init 
https://next.nutanix.com/blog-40/customizing-vms-with-cloud-init-on-nutanix-ahv-part-1-14573

A post which can help you write a commandlet for cloud-init 
https://next.nutanix.com/scripts-32/cloud-init-config-with-powershell-cmdlets-17931

A great article to use Sysprep to deploy Windows VM on AHV with configuration.

http://vzare.com/nutanix-mass-deployment-of-windows-2016-on-ahv-using-sysprep-answerfile-and-powershell/


 

Reply