# encoding: ascii
# api: powershell
# title: Find old snapshots
# description: 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.
# version: 0.1
# author: halr9000
# license: CC0
# x-poshcode-id: 1548
# x-archived: 2015-11-14T21:10:08
# x-published: 2010-12-19T14:04:00
#
#
param ( $Age = 30 )

Connect-VIServer vcenter.domain.com
$vm = Get-VM
$snapshots = Get-Snapshot -VM $vm
Write-Host -ForegroundColor Red "Old snapshots found:"
foreach ( $snap in $snapshots ) {
	if ( $snap.Created -lt (Get-Date).AddDays( -$Age ) ) {
		Write-Host "Name: " $snap.Name "  Size: " $snap.SizeMB "  Created: " $snap.Created
	}
}
