PoshCode Archive  Artifact [960f2e3398]

Artifact 960f2e339885d61aec1e690e5b53089bd730deed4ab72e51063f3ab2faad9e3c:

  • File Find-old-snapshots.ps1 — part of check-in [19241066de] at 2018-06-10 12:58:21 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: 809)

# 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
	}
}