PoshCode Archive  Artifact [ddc967239e]

Artifact ddc967239e6576468859e06a6fbd51681de42eceb72578d5a5fe30e74aaf26fe:

  • File Find-old-snapshots.ps1 — part of check-in [263e06740c] at 2018-06-10 13:37:54 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: 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
	}
}