PoshCode Archive  Artifact [aa03ddedb3]

Artifact aa03ddedb311cc0fb87c3fd6d611be817fc5ee880fc82822c64bf603fc424932:

  • File Find-old-snapshots.ps1 — part of check-in [5e6bac05b3] at 2018-06-10 14:00:22 on branch trunk — 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. (user: halr9000 size: 836)

# 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: 5737
# x-derived-from-id: 5738
# x-archived: 2015-10-16T20:59:22
# x-published: 2015-02-15T19: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
	}
}