Guest User

VM snapshot report

a guest
Aug 1st, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add-pssnapin VMware.VimAutomation.Core
  2.  
  3. #connect to the vcenter server
  4. Connect-VIServer $vcenter
  5.  
  6. #gets a list of snapshots from servers with $filter in the name
  7. $body = Get-Folder Datacenters| Get-VM -Name "*$filter*" | Get-Snapshot | Select VM, Name, @{N="sizemb";E={[math]::Round($_.SizeMb,0)}}, created  | Sort-Object VM, Name, created
  8.  
  9. $date = (get-date).ToString('MM/dd/yyyy')
  10.  
  11. #create HTML table based on results
  12. $htmlbody = "<html>"
  13. $htmlbody+='<HEAD>' + $Date + '</H>'
  14. $htmlbody+='<table border="1" cellspacing="2" width="55%">'
  15. $htmlbody+="<tr>"
  16. $htmlbody+="<td><b>VM Name</b></td>"
  17. $htmlbody+="<td><b>Snapshot Name</b></td>"
  18. $htmlbody+="<td><b>Size (MB)</b></td>"
  19. $htmlbody+="<td><b>Creation Date</b></td>"
  20. $htmlbody+="</tr>"
  21. #for loop creates each row of the table
  22. for($i=0;$i -lt $body.Count;$i++) {
  23.     $htmlbody+="<tr>"
  24.     $htmlbody+="<td>" + $body[$i].VM + "</td>"
  25.     $htmlbody+="<td>" + $body[$i].Name + "</td>"
  26.     $htmlbody+="<td>" + $body[$i].sizemb + "</td>"
  27.     $htmlbody+="<td>" + $body[$i].Created.ToString('MM/dd/yyyy HH:mm:ss') + "</td>"
  28.     $htmlbody+="</tr>"
  29. }
  30. $htmlbody+="</table>"
  31. $htmlbody+="</html>"
  32.  
  33.  
  34. Send-MailMessage -From $email_from -To $distroList -SmtpServer $smtp -Body $htmlbody -Subject "Snapshot Report" -BodyAsHtml
Advertisement
Add Comment
Please, Sign In to add comment