PoshCode Logo PowerShell Code Repository

Find old snapshots (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1548"></script>download | new post

Simple PowerCLI example to find old snapshots. Note that I would not actually use the techniques shown here, this script was intentionally written this way as a part of a training video in which I am building on techniques.

  1. param ( $Age = 30 )
  2.  
  3. Connect-VIServer vcenter.domain.com
  4. $vm = Get-VM
  5. $snapshots = Get-Snapshot -VM $vm
  6. Write-Host -ForegroundColor Red "Old snapshots found:"
  7. foreach ( $snap in $snapshots ) {
  8.         if ( $snap.Created -lt (Get-Date).AddDays( -$Age ) ) {
  9.                 Write-Host "Name: " $snap.Name "  Size: " $snap.SizeMB "  Created: " $snap.Created
  10.         }
  11. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me