# 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: 4188
# x-archived: 2015-10-16T21:05:22
# x-published: 2015-05-29T15:19: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
}
}