VMware vsPher eortamında snapshot’ların uzun süre kalması sanal makinelerin sağlığı açısından sorun çıkarabilmektedir. Belirli zamanlarda çalışacak bir script ile vSphere ortamında, üzerinde snapshot olan sanal makineleri bulup kendinize mail gönderebilirsiniz.
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
Import-Module VMware.PowerCLI
$vmcredential = Import-Clixml -Path "${env:\userprofile}\VMware-test.Cred"
Connect-VIServer 192.168.0.110 -Credential $vmcredential
$Snapshots = Get-vm | Get-Snapshot | where {$_.VM -notlike "*_replica"} | Sort-Object SizeGB | select VM,Description,PowerState,SizeGB | ConvertTo-Html -Property VM,Description,PowerState,SizeGB -Head $Header | Out-File c:\Script\SnapshotReport.html | ft -AutoSize
$snapshotvmlist = Get-Content C:\Script\SnapshotReport.html
$credential = Import-Clixml -Path "${env:\userprofile}\Mail-Cred.Cred"
Send-MailMessage -From "VMware Alert <vmware.alert@domain.com>" -To "taner@domain.com" -Subject "Snapshot VMs" -Body ($snapshotvmlist | Out-String) -BodyAsHtml -Priority High -dno onSuccess, onFailure -SmtpServer "mail.domain.com" -Port 587 -Credential $credential
Yukarıdaki script’i .ps1 uzantısı ile kaydedip, Windows Server üzerinde Task Scheduler’da 3 günde bir çalışacak şekilde ayarlarsanız snapshot’lar vSphere ortamınızda sizin için sorun olmaktan çıkacaktır. Script, C:\Script
dizini altında SnapshotReport.html
isimli bir HTML dosyada oluşturuyor.