vSphere snapshots capture the state of a virtual machine at a specific point in time. They are useful before applying patches, running upgrades, or making configuration changes that may need to be rolled back. Managing snapshots manually through the vSphere Client works for individual machines, but becomes slow and error-prone at scale.
PowerCLI gives you full control over snapshot lifecycle from the command line: creating, listing, reverting, and removing snapshots across multiple VMs in a single operation. This guide covers each of those tasks with practical examples.
Prerequisites
- PowerCLI installed and connected to vCenter or ESXi — see How to install VMware PowerCLI and connect to vSphere
- Sufficient permissions on the target VMs (snapshot operations require VM power user role or higher)
Quick answer
# Create a snapshot
New-Snapshot -VM "SRV-APP-01" -Name "Before patch" -Description "Pre-patch state" -Memory $false -Quiesce $false
# List snapshots for a VM
Get-Snapshot -VM "SRV-APP-01"
# Revert to a snapshot
Set-VM -VM "SRV-APP-01" -Snapshot (Get-Snapshot -VM "SRV-APP-01" -Name "Before patch") -Confirm:$false
# Remove a snapshot
Remove-Snapshot -Snapshot (Get-Snapshot -VM "SRV-APP-01" -Name "Before patch") -Confirm:$false
Step 1 — Connect to vCenter
All snapshot operations require an active session. Connect before running any of the commands below:
Connect-VIServer -Server vc01.vsphere.local
Step 2 — Create a snapshot
Use New-Snapshot to create a snapshot before a risky change. The -Name parameter is required and should be descriptive enough to identify the purpose later.
# Create a snapshot of a single VM before patching
New-Snapshot -VM "SRV-APP-01" -Name "Before patch 2024-03" -Description "Pre-patch snapshot, March maintenance window" -Memory $false -Quiesce $false
-Memory $false skips saving the VM’s memory state, which makes the snapshot faster and smaller. Use -Memory $true only if you need to resume the VM from the exact running state. -Quiesce $true requests filesystem quiescing via VMware Tools — useful before database or application snapshots, but requires VMware Tools to be installed and running.
To create snapshots across multiple VMs at once:
# Create a pre-patch snapshot for all VMs in a folder
Get-VM -Location "Production" | New-Snapshot -Name "Before patch 2024-03" -Memory $false -Quiesce $false
Step 3 — List snapshots
Use Get-Snapshot to inspect what snapshots exist for a VM:
# List all snapshots for a specific VM
Get-Snapshot -VM "SRV-APP-01"
# List snapshots for all VMs and show creation time and size
Get-VM | Get-Snapshot | Select-Object VM, Name, Description, Created, SizeGB | Format-Table -AutoSize
Step 4 — Revert to a snapshot
If a patch or change causes problems, revert the VM to its pre-change state:
# Revert SRV-APP-01 to the named snapshot
$snap = Get-Snapshot -VM "SRV-APP-01" -Name "Before patch 2024-03"
Set-VM -VM "SRV-APP-01" -Snapshot $snap -Confirm:$false
Step 5 — Remove a snapshot
Once you confirm a change was successful and the snapshot is no longer needed, remove it to reclaim datastore space:
# Remove a specific snapshot by name
$snap = Get-Snapshot -VM "SRV-APP-01" -Name "Before patch 2024-03"
Remove-Snapshot -Snapshot $snap -Confirm:$false
# Remove all snapshots for a VM (use with caution)
Get-Snapshot -VM "SRV-APP-01" | Remove-Snapshot -Confirm:$false
Step 6 — Find stale snapshots across the environment
A common maintenance task is identifying snapshots older than a threshold to clean up forgotten ones:
# Find all snapshots older than 7 days across all VMs
$threshold = (Get-Date).AddDays(-7)
Get-VM | Get-Snapshot | Where-Object { $_.Created -lt $threshold } | Select-Object VM, Name, Created, SizeGB | Format-Table -AutoSize
Export-Csv to save a report for review before deleting anything.
Step 7 — Disconnect when done
Disconnect-VIServer -Server * -Confirm:$false
Official reference
VMware PowerCLI — Broadcom Developer Portal
