Files
PowerCLI-Example-Scripts/PowerActions/Example - RemoveOldClusterSnapshots.ps1
Kamen Nikolov d70d246e34 Added Power Actions sample actions
Signed-off-by: Kamen Nikolov <knikolov@vmware.com>
2023-07-31 16:23:56 +03:00

17 lines
551 B
PowerShell

param (
[Parameter(Mandatory=$true)]
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster] $cluster,
[DateTime] $date)
if ($null -eq $date) {
$date = (Get-Date).AddDays(-7)
}
$vms = Get-VM -Location $cluster
foreach ($vm in $vms) {
$snaphostsToBeRemoved = Get-Snapshot -VM $vm | where {$_.Created -lt $date}
if ($null -ne $snaphostsToBeRemoved) {
Write-Host "Removing snapshots: " + $snaphostsToBeRemoved + " of VM: " + $vm
Remove-Snapshot $snaphostsToBeRemoved -Confirm:$false
}
}