Site icon Digital Thought Disruption

VMware Snapshot Management with PowerCLI: Detect, Report, and Clean Up

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:


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:\Reports\Snapshot_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:\Reports\Snapshot_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:\Reports\Snapshot_Audit_$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation
$report | Remove-Snapshot -Confirm:$false

Tips and Best Practices


Troubleshooting

ProblemSolution
Snapshot removal failsCheck for locked disks or active backup sessions
Get-Snapshot returns no dataEnsure vCenter permissions and VMware Tools are active
Snapshot size unknownUse $_.SizeMB and validate snapshot chain integrity
Orphaned snapshot still visible in GUIForce VM refresh using Get-View or vSphere Client
Exit mobile version