Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add-pssnapin VMware.VimAutomation.Core
- #connect to the vcenter server
- Connect-VIServer $vcenter
- #gets a list of snapshots from servers with $filter in the name
- $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
- $date = (get-date).ToString('MM/dd/yyyy')
- #create HTML table based on results
- $htmlbody = "<html>"
- $htmlbody+='<HEAD>' + $Date + '</H>'
- $htmlbody+='<table border="1" cellspacing="2" width="55%">'
- $htmlbody+="<tr>"
- $htmlbody+="<td><b>VM Name</b></td>"
- $htmlbody+="<td><b>Snapshot Name</b></td>"
- $htmlbody+="<td><b>Size (MB)</b></td>"
- $htmlbody+="<td><b>Creation Date</b></td>"
- $htmlbody+="</tr>"
- #for loop creates each row of the table
- for($i=0;$i -lt $body.Count;$i++) {
- $htmlbody+="<tr>"
- $htmlbody+="<td>" + $body[$i].VM + "</td>"
- $htmlbody+="<td>" + $body[$i].Name + "</td>"
- $htmlbody+="<td>" + $body[$i].sizemb + "</td>"
- $htmlbody+="<td>" + $body[$i].Created.ToString('MM/dd/yyyy HH:mm:ss') + "</td>"
- $htmlbody+="</tr>"
- }
- $htmlbody+="</table>"
- $htmlbody+="</html>"
- Send-MailMessage -From $email_from -To $distroList -SmtpServer $smtp -Body $htmlbody -Subject "Snapshot Report" -BodyAsHtml
Advertisement
Add Comment
Please, Sign In to add comment