Advertisement
qiwichupa

VM-snapshot-check.ps1

Jan 15th, 2012
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # emailing list of powered on VMs with snapshots
  2. # VmWare PowerCLI is required
  3.  
  4. $emailTo = "[email protected]"
  5. $smtpServer = "smtp_server"
  6. $vcenter_server = "vcenter_server"
  7.  
  8.  
  9.  
  10. Add-PSSnapin VMware.VimAutomation.Core
  11. Connect-VIServer -Server $vcenter_server
  12.  
  13. $VM_list = Get-VM | ForEach-Object {
  14.                         $snapshot_state = Get-Snapshot $_.Name
  15.                         if ( ($_.PowerState -eq 'PoweredOn') -and ($snapshot_state -ne $null) ) {
  16.                            "$_ `n"
  17.                         }
  18.                     }
  19.  
  20.  
  21.  
  22. $emailFrom = "VM snapshot checker <[email protected]>"
  23. $subject = "Powered On VMs with snapshots"
  24. $body = "$VM_list"
  25. $smtp = new-object Net.Mail.SmtpClient($smtpServer)
  26. if ($body -ne $null) { $smtp.Send($emailFrom, $emailTo, $subject, $body)}
  27.  
  28.  
  29. "ok"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement