Added Power Actions sample actions

Signed-off-by: Kamen Nikolov <knikolov@vmware.com>
This commit is contained in:
Kamen Nikolov
2023-07-31 16:23:56 +03:00
parent d41905e00f
commit d70d246e34
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
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
}
}