PowerShell Command Clone Virtual Machine | Nutanix Community
Skip to main content
Solved

PowerShell Command Clone Virtual Machine

  • November 5, 2019
  • 2 replies
  • 3250 views

Forum|alt.badge.img+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.

Best answer by HITESH0801

 

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!

View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

2 replies

HITESH0801
Nutanix Employee
Forum|alt.badge.img+5
  • Nutanix Employee
  • 104 replies
  • Answer
  • November 5, 2019

 

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!


HITESH0801
Nutanix Employee
Forum|alt.badge.img+5
  • Nutanix Employee
  • 104 replies
  • November 18, 2019

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/