Added Power Actions sample actions
Signed-off-by: Kamen Nikolov <knikolov@vmware.com>
This commit is contained in:
51
PowerActions/Example - ClusterSnapshotsReport.ps1
Normal file
51
PowerActions/Example - ClusterSnapshotsReport.ps1
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
param (
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster[]] $cluster,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string] $smtp,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string] $email)
|
||||||
|
|
||||||
|
$vms = Get-VM -Location $cluster
|
||||||
|
$snapshots = @()
|
||||||
|
foreach ($vm in $vms) {
|
||||||
|
$snapshots += Get-Snapshot -VM $vm
|
||||||
|
}
|
||||||
|
|
||||||
|
$header = @"
|
||||||
|
<style>
|
||||||
|
table {
|
||||||
|
font-size: 12px;
|
||||||
|
border: 0px;
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 4px;
|
||||||
|
margin: 0px;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
background: #395870;
|
||||||
|
background: linear-gradient(#49708f, #293f50);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 11px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
padding: 10px 15px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
tbody tr:nth-child(even) {
|
||||||
|
background: #f0f0f2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
"@
|
||||||
|
|
||||||
|
$snapshots | select Name,VM,Created,@{Name="Size";Expression={[math]::Round($_.SizeMB,3)}},IsCurrent | `
|
||||||
|
ConvertTo-Html -head $header | Out-File "SnapshotReport.html"
|
||||||
|
|
||||||
|
Send-MailMessage -from "Snapshot Reports <noreply@vmware.com>" `
|
||||||
|
-to $email `
|
||||||
|
-subject "Snapshot Report" `
|
||||||
|
-body "Cluster snapshot report" `
|
||||||
|
-Attachment "SnapshotReport.html" `
|
||||||
|
-smtpServer $smtp
|
||||||
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