How to manage vSphere snapshots with PowerCLI (Walk-through)

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

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
Note: -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
Warning: Old snapshots consume datastore space and grow over time as the VM writes new data. A snapshot that was small at creation can become several gigabytes after days of VM activity. Regularly auditing snapshots with the command above helps prevent datastore capacity issues.

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
Warning: Reverting a snapshot powers off the VM if it is currently running, then restores it to the snapshot state. Any changes made after the snapshot was taken will be lost. Confirm you are targeting the correct snapshot before running this command.

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
Important: Removing a snapshot commits the changes from that snapshot into the parent disk. This operation can be slow for large or old snapshots and places I/O load on the datastore during consolidation. Schedule removals during low-activity windows in production environments.

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
Note: This command reads from all VMs visible to the connected vCenter. In large environments, it may take a minute or two to complete. Pipe the output to 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

Related guides