VMware Cloud Community
ranjitcool
Hot Shot
Hot Shot

Clone vm from Powercli

Hey Guys,

1. I wanted to clone a vm to a new vm using powercli. Not into scripts yet so doing command line.

I tried the New-vm cmdlet but it confused me a lot.

Also I connected to the vcenter but was unable to display all hosts or clusters within it.

connect-viserver -server vcenter -protocol https -user username -password pass

2. How do I get list of all datacenters in a vc, then hosts, then vms.

I am trying to use vcli more often to get familiar with it.

Thanks

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
1 Reply
LucD
Leadership
Leadership

A small correction, the Connect-VIServer cmdlet is PowerCLI, not vCLI.

To see datacenters, hosts and guest, you can do (after the COnnect-VIServer)

Get-Datacenter

Get-VMHost

Get-VM

If you want this information together, you can execute the following small script

foreach($dc in Get-Datacenter){
    foreach($esx in Get-VMHost -Location $dc){
        Get-VM -Location $esx | Select @{N="Datacenter";E={$dc.Name}},@{N="VMHost";E={$esx.Name}},@{N="VM";E={$_.Name}}
    }
}

The New-VM cmdlet allows you to clone a VM with the VM parameter.

See Example 4


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos