This page is a structured reference for the most commonly used VMware PowerCLI cmdlets, organized by task area. Each entry includes the cmdlet name, its purpose, and a practical usage example. Use it as a quick lookup during scripting or troubleshooting sessions.
Note: All commands on this page assume an active connection to vCenter or ESXi established with
Connect-VIServer. See How to install VMware PowerCLI and connect to vSphere for setup instructions.
Connection
# Connect to vCenter or ESXi host
Connect-VIServer -Server vc01.vsphere.local
# Disconnect from all connected servers
Disconnect-VIServer -Server * -Confirm:$false
# Disconnect from a specific server
Disconnect-VIServer -Server vc01.vsphere.local -Confirm:$false
# Check active connections
$global:DefaultVIServers
Virtual machines
# List all VMs
Get-VM
# Get a specific VM by name
Get-VM -Name "SRV-APP-01"
# Get VMs from a specific folder
Get-VM -Location "Production"
# Get VMs from a specific cluster
Get-Cluster "CL-PROD-01" | Get-VM
# Get VMs from a specific host
Get-VMHost "esxi01.vsphere.local" | Get-VM
# Filter powered-on VMs
Get-VM | Where-Object { $_.PowerState -eq "PoweredOn" }
# Show VM name, CPU, memory, and host
Get-VM | Select-Object Name, NumCpu, MemoryGB, @{N="Host"; E={$_.VMHost}} | Format-Table -AutoSize
# Power on a VM
Start-VM -VM "SRV-APP-01" -Confirm:$false
# Power off a VM (hard power off)
Stop-VM -VM "SRV-APP-01" -Confirm:$false
# Shut down guest OS (requires VMware Tools)
Shutdown-VMGuest -VM "SRV-APP-01" -Confirm:$false
# Restart guest OS (requires VMware Tools)
Restart-VMGuest -VM "SRV-APP-01" -Confirm:$false
Snapshots
# List snapshots for a VM
Get-Snapshot -VM "SRV-APP-01"
# List snapshots across all VMs with size and date
Get-VM | Get-Snapshot | Select-Object VM, Name, Created, SizeGB | Format-Table -AutoSize
# Create a snapshot
New-Snapshot -VM "SRV-APP-01" -Name "Before patch" -Memory $false -Quiesce $false
# Revert to a snapshot
$snap = Get-Snapshot -VM "SRV-APP-01" -Name "Before patch"
Set-VM -VM "SRV-APP-01" -Snapshot $snap -Confirm:$false
# Remove a specific snapshot
$snap = Get-Snapshot -VM "SRV-APP-01" -Name "Before patch"
Remove-Snapshot -Snapshot $snap -Confirm:$false
# Find snapshots older than 7 days
$threshold = (Get-Date).AddDays(-7)
Get-VM | Get-Snapshot | Where-Object { $_.Created -lt $threshold } | Select-Object VM, Name, Created, SizeGB
Hosts (ESXi)
# List all ESXi hosts
Get-VMHost
# Show host name, connection state, and version
Get-VMHost | Select-Object Name, ConnectionState, Version | Format-Table -AutoSize
# Get hosts in a specific cluster
Get-Cluster "CL-PROD-01" | Get-VMHost
# Put a host into maintenance mode
Set-VMHost -VMHost "esxi01.vsphere.local" -State Maintenance -Confirm:$false
# Exit maintenance mode
Set-VMHost -VMHost "esxi01.vsphere.local" -State Connected -Confirm:$false
Datastores
# List all datastores
Get-Datastore
# Show datastore name, capacity, and free space
Get-Datastore | Select-Object Name, CapacityGB, FreeSpaceGB | Format-Table -AutoSize
# Find datastores with less than 20% free space
Get-Datastore | Where-Object { ($_.FreeSpaceGB / $_.CapacityGB) -lt 0.2 } | Select-Object Name, CapacityGB, FreeSpaceGB
Networking
# List virtual switches on a host
Get-VirtualSwitch -VMHost "esxi01.vsphere.local"
# List port groups
Get-VirtualPortGroup
# Get network adapters for a VM
Get-NetworkAdapter -VM "SRV-APP-01"
# List distributed switches
Get-VDSwitch
Resource pools and clusters
# List all clusters
Get-Cluster
# List resource pools
Get-ResourcePool
# Get VMs in a resource pool
Get-ResourcePool "RP-PROD" | Get-VM
Reporting and export
# Export VM inventory to CSV
Get-VM | Select-Object Name, PowerState, NumCpu, MemoryGB | Export-Csv -Path "C:\Reports\vms.csv" -NoTypeInformation
# Export datastore usage to CSV
Get-Datastore | Select-Object Name, CapacityGB, FreeSpaceGB | Export-Csv -Path "C:\Reports\datastores.csv" -NoTypeInformation
# Export snapshot report to CSV
Get-VM | Get-Snapshot | Select-Object VM, Name, Created, SizeGB | Export-Csv -Path "C:\Reports\snapshots.csv" -NoTypeInformation
PowerCLI configuration
# Disable CEIP prompt for current user
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
# Ignore SSL certificate errors for current session
Set-PowerCLIConfiguration -Scope Session -InvalidCertificateAction Ignore
# Ignore SSL certificate errors permanently for current user
Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction Ignore
# View current PowerCLI configuration
Get-PowerCLIConfiguration
Official reference
VMware PowerCLI — Broadcom Developer Portal
