Files
PowerCLI-Example-Scripts/PowerActions/Example - RemoveOldClusterSnapshots.ps1
Kamen Nikolov ce06c5372b Added git sync script and fixed an issue in the
remove old snapshots script in the PowerActions folder
2023-11-21 16:55:06 +02:00

17 lines
544 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
}
}