VMware PowerCLI Cheat Sheet

Quick reference

Module (vSphere 9 / VCF 9)
VCF.PowerCLI
Module (vSphere 7 and 8)
VMware.PowerCLI
Install
Install-Module VCF.PowerCLI
Connect
Connect-VIServer vcenter.example.com
Active connections
$global:DefaultVIServers
Disconnect
Disconnect-VIServer -Server * -Confirm:$false
Which module: Broadcom renamed the module from VMware.PowerCLI to VCF.PowerCLI with VCF PowerCLI 9.0 in June 2025. The guidance is to uninstall the old module and install the new one rather than upgrade in place. PowerCLI 13.3 and earlier run on Windows PowerShell 5.1 or PowerShell 7.x; Broadcom now names PowerShell 7.4 as the minimum recommended version and is phasing 5.1 out.

Install and connect

TaskCommand
Install from PowerShell GalleryInstall-Module -Name VCF.PowerCLI -Scope CurrentUser
UpdateUpdate-Module -Name VCF.PowerCLI
Verify it is presentGet-Module -Name VCF.PowerCLI -ListAvailable
Install alongside an old VMware.PowerCLIInstall-Module VCF.PowerCLI -AllowClobber -SkipPublisherCheck
Accept a self-signed vCenter certificateSet-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
Turn off the CEIP promptSet-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm:$false
Show current configurationGet-PowerCLIConfiguration
Connect with a prompt for credentialsConnect-VIServer vcenter.example.com -Credential (Get-Credential)
Connect and store the credentialConnect-VIServer vcenter.example.com -SaveCredentials
Connect to several vCentersConnect-VIServer vc01, vc02
Disconnect from allDisconnect-VIServer -Server * -Confirm:$false
SkipPublisherCheck: Broadcom signs the module with its own certificate instead of the old VMware one. Without -SkipPublisherCheck the install can fail on a machine that still has modules signed by VMware.

Find things in the inventory

TaskCommand
All VMsGet-VM
One VMGet-VM -Name web01
VMs by name patternGet-VM -Name "web*"
Powered-on VMs onlyGet-VM | Where-Object {$_.PowerState -eq 'PoweredOn'}
VMs on one hostGet-VMHost esx01.example.com | Get-VM
VMs in one clusterGet-Cluster PROD | Get-VM
All hostsGet-VMHost
Clusters, datacenters, foldersGet-Cluster · Get-Datacenter · Get-Folder
DatastoresGet-Datastore
Resource poolsGet-ResourcePool
Everything a VM is made ofGet-VM web01 | Format-List *
Guest OS details (needs VMware Tools)Get-VMGuest -VM web01
Pipelines are the point: Almost every Get- cmdlet accepts objects from another. Get-Cluster PROD | Get-VMHost | Get-VM reads left to right and needs no loops.

VM power and lifecycle

TaskCommand
Power onStart-VM -VM web01
Graceful guest shutdownShutdown-VMGuest -VM web01 -Confirm:$false
Hard power offStop-VM -VM web01 -Confirm:$false
Restart the guest OSRestart-VMGuest -VM web01 -Confirm:$false
SuspendSuspend-VM -VM web01 -Confirm:$false
Create a VMNew-VM -Name web02 -VMHost esx01 -Datastore ds01 -NumCpu 2 -MemoryGB 4 -DiskGB 40
Clone from a templateNew-VM -Name web03 -Template tpl-2022 -VMHost esx01 -Datastore ds01
vMotion to another hostMove-VM -VM web01 -Destination esx02
Storage vMotionMove-VM -VM web01 -Datastore ds02
Delete from diskRemove-VM -VM web01 -DeletePermanently -Confirm:$false
Stop-VM is the power cable: Stop-VM cuts power with no guest shutdown. Use Shutdown-VMGuest for anything with a running OS, and keep Stop-VM for a guest that has already stopped responding.

VM configuration

TaskCommand
Change CPU and memorySet-VM -VM web01 -NumCpu 4 -MemoryGB 8 -Confirm:$false
List disksGet-HardDisk -VM web01
Add a thin diskNew-HardDisk -VM web01 -CapacityGB 100 -StorageFormat Thin
Grow a diskGet-HardDisk -VM web01 | Where-Object {$_.Name -eq "Hard disk 2"} | Set-HardDisk -CapacityGB 200 -Confirm:$false
List network adaptersGet-NetworkAdapter -VM web01
Move an adapter to another port groupGet-NetworkAdapter -VM web01 | Set-NetworkAdapter -NetworkName "VLAN10" -Confirm:$false
Mount an ISOGet-CDDrive -VM web01 | Set-CDDrive -IsoPath "[ds01] iso/win.iso" -Connected $true -Confirm:$false
Disconnect the CD driveGet-CDDrive -VM web01 | Set-CDDrive -NoMedia -Confirm:$false
Upgrade VMware ToolsUpdate-Tools -VM web01

Snapshots

TaskCommand
List a VM snapshotsGet-Snapshot -VM web01
Every snapshot in the environmentGet-VM | Get-Snapshot
Snapshots older than seven daysGet-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-7)}
Total space used by snapshotsGet-VM | Get-Snapshot | Measure-Object -Property SizeGB -Sum
CreateNew-Snapshot -VM web01 -Name "pre-patch" -Description "before September patching"
Create with a quiesced filesystemNew-Snapshot -VM web01 -Name "pre-patch" -Quiesce
Delete oneGet-Snapshot -VM web01 -Name "pre-patch" | Remove-Snapshot -Confirm:$false
Delete a snapshot and its childrenGet-Snapshot -VM web01 -Name "pre-patch" | Remove-Snapshot -RemoveChildren -Confirm:$false
RevertSet-VM -VM web01 -Snapshot "pre-patch" -Confirm:$false
Snapshots are not backups: A snapshot grows a delta file for as long as it exists and consolidation gets slower the longer you wait. The aging query above is the one worth putting in a scheduled report.

Hosts and clusters

TaskCommand
Host summaryGet-VMHost | Select-Object Name,ConnectionState,PowerState,Version,Build
Enter maintenance modeSet-VMHost -VMHost esx01 -State Maintenance -Confirm:$false
Leave maintenance modeSet-VMHost -VMHost esx01 -State Connected -Confirm:$false
Reboot a hostRestart-VMHost -VMHost esx01 -Confirm:$false
Host servicesGet-VMHostService -VMHost esx01
Start SSH on a hostGet-VMHostService -VMHost esx01 | Where-Object {$_.Key -eq 'TSM-SSH'} | Start-VMHostService
Rescan all HBAsGet-VMHostStorage -VMHost esx01 -RescanAllHba
Hardware inventoryGet-VMHost esx01 | Get-VMHostHardware
Cluster settingsGet-Cluster | Select-Object Name,HAEnabled,DrsEnabled,DrsAutomationLevel
Run esxcli against a host$e = Get-EsxCli -VMHost esx01 -V2 then $e.system.version.get.Invoke()
Get-EsxCli -V2: Always pass -V2. The version 1 interface is positional and breaks silently when a namespace changes between ESXi releases; V2 takes a named argument hashtable from $e.<namespace>.CreateArgs().

Storage and datastores

TaskCommand
Datastore usageGet-Datastore | Select-Object Name,@{N="FreeGB";E={[math]::Round($_.FreeSpaceGB)}},@{N="TotalGB";E={[math]::Round($_.CapacityGB)}}
Which VMs live on a datastoreGet-Datastore ds01 | Get-VM
Datastore clustersGet-DatastoreCluster
Host storage viewGet-VMHostStorage -VMHost esx01
Thin-provisioned disksGet-VM | Get-HardDisk | Where-Object {$_.StorageFormat -eq 'Thin'}
Browse a datastoreNew-PSDrive -Name ds -PSProvider VimDatastore -Root "\\" -Location (Get-Datastore ds01)

Networking

TaskCommand
Standard switches on a hostGet-VirtualSwitch -VMHost esx01
Port groupsGet-VirtualPortGroup -VMHost esx01
Physical and VMkernel adaptersGet-VMHostNetworkAdapter -VMHost esx01
Distributed switchesGet-VDSwitch
Distributed port groupsGet-VDPortgroup
Which VMs use a port groupGet-VM | Get-NetworkAdapter | Where-Object {$_.NetworkName -eq "VLAN10"}
VMkernel addressesGet-VMHostNetworkAdapter -VMHost esx01 -VMKernel | Select-Object Name,IP,SubnetMask,Mtu

Reporting, events and performance

TaskCommand
VM inventory to CSVGet-VM | Select-Object Name,PowerState,NumCpu,MemoryGB,@{N="UsedGB";E={[math]::Round($_.UsedSpaceGB)}} | Export-Csv vms.csv -NoTypeInformation
Recent vCenter eventsGet-VIEvent -MaxSamples 100
Events for one VMGet-VM web01 | Get-VIEvent -MaxSamples 50
Who powered off a VMGet-VM web01 | Get-VIEvent -Types Info | Where-Object {$_.FullFormattedMessage -match "power"}
Live CPU statisticsGet-Stat -Entity (Get-VM web01) -Stat cpu.usage.average -Realtime -MaxSamples 10
Host memory over the last dayGet-Stat -Entity (Get-VMHost esx01) -Stat mem.usage.average -Start (Get-Date).AddDays(-1)
VMware Tools status everywhereGet-VM | Select-Object Name,@{N="Tools";E={$_.ExtensionData.Guest.ToolsStatus}}
Reaching further: When no cmdlet exposes a property, Get-VM web01 | Get-View returns the underlying managed object, and $vm.ExtensionData reaches the same data from an object you already have.

FAQ

Should I install VMware.PowerCLI or VCF.PowerCLI?
Use VCF.PowerCLI for VMware Cloud Foundation 9 and vSphere 9. Keep VMware.PowerCLI 13.x for vSphere 7 and 8 estates that have not moved yet. Broadcom advises uninstalling the old module before installing the new one rather than upgrading over the top, because duplicate cmdlet names cause conflicts.
Do I need PowerShell 7?
PowerCLI 13.3 and earlier work on Windows PowerShell 5.1 as well as PowerShell 7.x. Broadcom now names PowerShell 7.4 as the minimum recommended version and is phasing out 5.1 support, so new automation is worth writing on 7.x. On Linux and macOS PowerShell 7 has always been the only option.
Connect-VIServer fails with a certificate error
vCenter ships with a self-signed certificate that PowerShell does not trust. Either install the vCenter root certificate on the machine running PowerCLI, or set Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false. The first is correct for anything scheduled; the second is fine on an admin workstation.
A cmdlet keeps asking for confirmation
Most cmdlets that change state have a confirmation prompt. Add -Confirm:$false per command, or set it once for the session with Set-PowerCLIConfiguration -Confirm:$false. Do not put that in a script somebody else will run.
How do I run an esxcli command through PowerCLI?
Get a handle with $e = Get-EsxCli -VMHost esx01 -V2, then call the namespace path as a method, for example $e.network.nic.list.Invoke(). Arguments go in a hashtable built by $e.<namespace>.CreateArgs().