Solved

PowerShell Command Clone Virtual Machine

  • 5 November 2019
  • 2 replies
  • 3037 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.

icon

Best answer by HITESH0801 5 November 2019, 18:36

View original

This topic has been closed for comments

2 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!

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/