VMware PowerCLI Command Generator

Tick a few options and get PowerCLI that runs: VMs, snapshots, ESXi networking and esxcli, every cmdlet explained.

This VMware PowerCLI command generator turns a handful of choices into a vSphere script you can paste and run, because a real task is almost never one cmdlet. Pick a job: create or clone a VM, take and remove snapshots, build ESXi virtual switches and VMkernel adapters, or run host operations and esxcli through PowerCLI. The output stitches the full sequence together, starting from a Connect-VIServer session, and every line carries a plain-English note on what it does. Presets cover the everyday runs, a new Linux VM, a pre-patch snapshot, a vMotion VMkernel, a storage rescan. Everything is built in your browser, so server names, VM names and datastore paths never leave the page.

100% in your browser. Nothing you type ever leaves this page.

VMware PowerCLI command generator

Nobody remembers every flag on New-VM. Or New-VMHostNetworkAdapter, honestly. So tick the options here and you get PowerCLI that runs: spin up and manage vSphere VMs, grab snapshots, wire ESXi networking, fire off esxcli. Each cmdlet comes with a one-line note on what it actually does. It all happens in your browser, nothing leaves the page.

What this PowerCLI generator does

PowerCLI is the PowerShell module for driving vSphere from a terminal. It's how you script the stuff you'd otherwise click through hundreds of times in the vSphere Client. Here's the snag, though. A real task is almost never one cmdlet. Creating a VM means New-VM with the right host, the right datastore, disk format, guest id, network, and then usually New-CDDrive plus Start-VM on top. This thing stitches the whole sequence together from a handful of choices, so what you copy actually runs start to finish. Each cmdlet gets a plain-English note too.

It handles the four jobs I reach for most around vSphere. VM lifecycle. Snapshots. Host networking, meaning the virtual switches and port groups and VMkernel adapters. And host operations, which includes running esxcli through PowerCLI. Every script kicks off from a Connect-VIServer session, because that's the first thing any PowerCLI script needs anyway.

Getting started with PowerCLI

Install the module once from an elevated PowerShell: Install-Module VMware.PowerCLI -Scope CurrentUser. Then connect with Connect-VIServer -Server vcenter.example.com and you're in. If you've got vCenter, point at that instead of the individual hosts, so cluster features like vMotion and DRS stay on the table for your scripts. Lab box with a self-signed cert? Run Set-PowerCLIConfiguration -InvalidCertificateAction Ignore first or the connect just whines at you.

The cmdlets behind common tasks

TaskCmdlet
ConnectConnect-VIServer
Create a VMNew-VM (with -DiskGB, -MemoryGB, -NumCpu, -GuestId, -NetworkName)
Clone from a templateNew-VM -Template
SnapshotNew-Snapshot, Get-Snapshot, Remove-Snapshot
Virtual switch and port groupNew-VirtualSwitch, New-VirtualPortGroup
VMkernel adapterNew-VMHostNetworkAdapter
Run esxcliGet-EsxCli -V2

esxcli through PowerCLI

Pretty much anything you'd type into the ESXi shell with esxcli, you can drive remotely instead. Get-EsxCli -VMHost host -V2 hands you back an object whose namespaces mirror the esxcli tree. So $esxcli.network.nic.list.Invoke() lists the physical NICs, and $esxcli.storage.core.adapter.rescan.Invoke() rescans storage. The win here is reaching esxcli the scriptable, credential-managed way, no SSH enabled on every single host. Which, if you've ever had to audit who left SSH running where, you'll appreciate.

Privacy and how this tool runs

JavaScript builds the script right here in your browser. Your server names, VM names, datastore paths: none of it gets sent off or logged, full stop. Once the page has loaded you can even yank the network cable and it keeps working offline.

Sources and further reading

Frequently asked questions

How do I create a VM with PowerCLI?

Connect first with Connect-VIServer. Then New-VM -Name web01 -VMHost esxi01 -Datastore datastore1 -NumCpu 2 -MemoryGB 4 -DiskGB 40 -GuestId rhel9_64Guest -NetworkName "VM Network", and cap it off with Start-VM web01. The generator above just builds that whole run for you with your own values dropped in.

Should I connect PowerCLI to vCenter or to an ESXi host?

vCenter, basically always, if you have one. That is what keeps cluster features like vMotion and DRS and HA within reach, plus you can aim at any host from a single session. Going straight at an ESXi host is for genuinely standalone boxes, or for the bad day when vCenter itself is down.

How do I take and remove a snapshot in PowerCLI?

To make one: New-Snapshot -VM web01 -Name pre-patch -Quiesce. To see what is there: Get-Snapshot -VM web01. To clean it up: Get-Snapshot -VM web01 -Name pre-patch piped into Remove-Snapshot -Confirm:$false. Tack on -Memory if you want the live memory state captured too, though that one is slower and I would skip it unless you really need it.

How do I run esxcli commands from PowerCLI?

Grab the object first: $esxcli = Get-EsxCli -VMHost esxi01 -V2. Then walk the namespace, say $esxcli.network.nic.list.Invoke() or $esxcli.storage.core.adapter.rescan.Invoke(). It mirrors the esxcli tree node for node, and you never have to turn SSH on.

What GuestId should I use?

GuestId is how you tell ESXi which OS to tune itself for. It drives defaults, the SCSI controller, the NIC type, that sort of thing. Just pick the closest match: rhel9_64Guest, ubuntu64Guest, windows2019srvNext_64Guest, whatever fits. And honestly, get it wrong and the VM still boots fine, you just end up with slightly worse virtual hardware than you could have had.