Blog a Week - 2018

Weekly Snapshot Report PowerCli (BAW8)

I know that a lot of people have provided snapshot reports in the past for vSphere, but a lot of them were not really suitable to work with on a regular basis.  Therefore I pulled together a short script that will list all snapshots for virtual machines that are powered on – as these are the ones where the snapshots should not sit in place for any length of time.
Here is a screenshot of the report and the script is below:

 

[powershell]

</pre>
# HTML Stuff
$datetoday = [DateTime]::Today.ToString("ddd d MMM yyy")

$headerObj = @"
<!DOCTYPE html>
<html>
<head>
<title>"Snapshot Report – $datetoday</title>
<style>
body {font-family: Tahoma; background-color:#ffffff;}
table {font-family: Tahoma;width: $($rptWidth)%;font-size: 12px;border-collapse:collapse;}
<!– table tr:nth-child(odd) td {background: #e2e2e2;} –>
th {background-color: #e2e2e2;border: 1px solid #a7a9ac;border-bottom: none;}
td {background-color: #ffffff;border: 1px solid #a7a9ac;padding: 2px 3px 2px 3px;}
</style>
</head>
"@

$bodyTop = @"
<body>
<center>

<table>
<tr>
<td style="width: 100%;height: 12px;border: none;background-color: #143d63;color: White;font-size: 12px;vertical-align: bottom;text-align: right;padding: 0px 5px 0px 0px;"Report generated on $(Get-Date -format g)</td>
</tr>
<tr>
<td style="width: 100%;height: 24px;border: none;background-color: #ffffff;color: Black;font-size: 24px;vertical-align: bottom;text-align: center;padding: 0px 0px 0px 15px;">Snapshot Report – $datetoday</td>

</tr>
<tr>
<td style="width: 100%;height: 12px;border: none;background-color: #143d63;color: White;font-size: 12px;vertical-align: bottom;text-align: right;padding: 0px 5px 0px 0px;"></td>
</tr>
<tr>
<td style="width: 50%;height: 12px;border: none;background-color: ZZhdbgZZ;color: White;font-size: 12px;vertical-align: bottom;text-align: left;padding: 0px 0px 2px 5px;"></td>
<td style="width: 50%;height: 12px;border: none;background-color: ZZhdbgZZ;color: White;font-size: 12px;vertical-align: bottom;text-align: right;padding: 0px 5px 2px 0px;">MVR v</td>
</tr>
</table>
"@

$subHead01 = @"
<table>
<tr>
<td style="height: 35px;background-color: #f3f4f4;color: #626365;font-size: 16px;padding: 5px 0 0 15px;border-top: 5px solid white;border-bottom: none;">
"@

$subHead01suc = @"
<table>
<tr>
<td style="height: 35px;background-color: #00b050;color: #ffffff;font-size: 16px;padding: 5px 0 0 15px;border-top: 5px solid white;border-bottom: none;">
"@

$subHead01war = @"
<table>
<tr>
<td style="height: 35px;background-color: #ffd96c;color: #ffffff;font-size: 16px;padding: 5px 0 0 15px;border-top: 5px solid white;border-bottom: none;">
"@

$subHead01err = @"
<table>
<tr>
<td style="height: 35px;background-color: #FB9895;color: #ffffff;font-size: 16px;padding: 5px 0 0 15px;border-top: 5px solid white;border-bottom: none;">
"@

$subHead02 = @"
</td>
</tr>
</table>
"@

$HTMLbreak = @"
<table>
<tr>
<td style="height: 10px;background-color: #626365;padding: 5px 0 0 15px;border-top: 5px solid white;border-bottom: none;"></td>
</tr>
</table>
"@

$footerObj = @"
<table>
<tr>
<td style="height: 15px;background-color: #ffffff;border: none;color: #626365;font-size: 10px;text-align:center;</a></td>
</tr>
</table>
</center>
</body>
</html>
"@

get-module -ListAvailable VM* | Import-Module

connect-viserver #enter vcenter name here

$bodySummaryRp = get-vm | Where-Object {$_.PowerState -eq "PoweredOn"} | get-snapshot | select vm, name, description, created, @{N="SizeGB";E={[math]::round($_.sizegb, 2)}} | sort vm | ConvertTo-Html -fragment

$htmloutput = $headerObj + $bodyTop + $BodySummHeader + $bodySummaryRp

$htmlOutput | out-file #enter output directory here

Disconnect-VIServer #enter vcenter name here -Confirm:$false

$Email = $htmlOutput

$smtpServer = #enter email smtp server name here
[string[]]$to = #enter email address to send report to
$from = #enter email address to send report from
$subject = "Snapshot Report – $DateToday"
$body = ""
$body += $Email

Send-MailMessage -SmtpServer $smtpServer -To $to -From $from -Subject $subject -Body $body -BodyAsHtml
<pre>

[/powershell]

 

Blog-a-Week 2018 Posting (BAW):

In previous years, I have had periods throughout the year where I have been unable to post an entry to my blog.  During 2018, my aim is to post a blog entry each week of the year.  I’m hoping that the blog entries will all be useful bits of information or items that I’ve been working on recently but if the standard of the entries drops, I apologise now, as this could have been a busy week and I wasn’t able to put in as much time as I would have liked into the post

1 thought on “Weekly Snapshot Report PowerCli (BAW8)

Leave a Reply

Your email address will not be published. Required fields are marked *