Added Power Actions sample actions
Signed-off-by: Kamen Nikolov <knikolov@vmware.com>
This commit is contained in:
17
PowerActions/Example - RemoveOldClusterSnapshots.ps1
Normal file
17
PowerActions/Example - RemoveOldClusterSnapshots.ps1
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user