Introduction

Snapshots are a powerful tool in any vSphere environment, but unmanaged snapshots can consume storage, degrade performance, and cause backup failures. Manually reviewing snapshots across hundreds of VMs is inefficient. PowerCLI provides full visibility and control over snapshot lifecycle management.

In this article, you’ll learn to:

  • Detect snapshots across your environment
  • Report snapshot age and owner details
  • Export results to CSV or HTML
  • Remove old or orphaned snapshots automatically
  • Build a scheduled snapshot audit script

Step 1: List All Snapshots in vCenter

Get-VM | Get-Snapshot

Include name, size, and creation date:

Get-VM | Get-Snapshot | Select VM, Name, Created, SizeMB

Step 2: Find Snapshots Older Than X Days

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-7)}

Filter snapshots older than 14 days and sort by date:

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-14)} | Sort-Object Created

Step 3: Export Snapshot Report to CSV

Get-VM | Get-Snapshot | Select VM, Name, Created, SizeMB | Export-Csv "C:ReportsSnapshot_Audit.csv" -NoTypeInformation

Step 4: Generate an HTML Snapshot Dashboard (Optional)

Get-VM | Get-Snapshot | Select VM, Name, Created, SizeMB | ConvertTo-Html -Title "Snapshot Dashboard" | Out-File "C:ReportsSnapshot_Report.html"

Step 5: Remove Old Snapshots Automatically

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-14)} | Remove-Snapshot -Confirm:$false

Only target powered-off VMs (optional):

Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | Get-Snapshot | Remove-Snapshot -Confirm:$false

Diagram: Snapshot Lifecycle Workflow


Use Case: Weekly Compliance Snapshot Audit

  1. List all snapshots
  2. Export report for team review
  3. Remove all snapshots older than 10 days
  4. Schedule using Task Scheduler or cron

Sample script:

$report = Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-10)}
$report | Export-Csv "C:ReportsSnapshot_Audit_$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation
$report | Remove-Snapshot -Confirm:$false

Tips and Best Practices

  • Snapshots are not backups. Use them temporarily only
  • Do not use snapshots with large or high-I/O VMs for extended periods
  • Always verify snapshot removal has completed
  • Monitor snapshot storage usage weekly

Troubleshooting

Problem Solution
Snapshot removal fails Check for locked disks or active backup sessions
Get-Snapshot returns no data Ensure vCenter permissions and VMware Tools are active
Snapshot size unknown Use $_.SizeMB and validate snapshot chain integrity
Orphaned snapshot still visible in GUI Force VM refresh using Get-View or vSphere Client

Similar Posts