Introduction

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

Get-VM | Get-Snapshot

In this article, you’ll learn to:

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


Step 2: Find Snapshots Older Than X Days

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.

$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