Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add-pssnapin VMware.VimAutomation.Core
- $vcenter = "<vcenter fqdn>"
- $email_from = "<from smtp address>"
- $distroList = "<to smtp address>"
- $subject = $vcenter + " - Weekly snapshot report"
- $smtp = "<smtp server>"
- #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, VM.Folder, VM.Notes | Sort-Object VM, Name, created, VM.Folder, VM.Notes
- $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="75%">'
- $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+="<td><b>Folder</b></td>"
- $htmlbody+="<td><b>Notes</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+="<td>" + $body[$i].VM.Folder + "</td>"
- $htmlbody+="<td>" + $body[$i].VM.Notes + "</td>"
- $htmlbody+="</tr>"
- }
- $htmlbody+="</table>"
- $htmlbody+="</html>"
- Send-MailMessage -From $email_from -To $distroList -SmtpServer $smtp -Body $htmlbody -Subject $subject -BodyAsHtml
Advertisement
Add Comment
Please, Sign In to add comment