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:

 


</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>

 

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

About the Author

Dinger

I have been in IT for the past 15 years and using virtualisation technologies for around the past 8 years. I started, as quite a lot of people do, working with PCs after playing with such iconic systems like the ZX81, ZX Spectrum and then progressing through 386s, 486s, Pentiums etc. After being headhunted at sixth form to work for a small company based around Hertfordshire, UK. I began working with small businesses and gaining a lot of hardware experience. Three years later, after helping to increase the size of the business, I needed to gain exposure to a larger environment to progress my own career. I joined a large manufacturing company around Electronic Test and Measurement which progressed my skills onto more PC work, hardware work and then onto Server Operating Systems. I progressed again onto a consultancy company based in Reading, UK. Initially working as an engineer performing hardware / software installations for larger companies contracted out to the consultancy company, I moved up into a Consultant position continuing my travel across the UK assisting and providing solutions to companies. I finally moved on again to my current position, working back in Hertfordshire, UK. Again working for a large manufacturing company, this time with over 50,000 users worldwide. I am responsible for the datacenter hardware, the storage environment, the vmware environment and also implementing their new Citrix XenApp farm. My days are busy but also productive, its a friendly environment and in my four years of being with the company, I have seen many changes in technology and infrastructure in use within the company. About the site I started this site as I had been thinking of having more of a presence on the web for a while. On a daily basis, I perform tasks and use tools that others may not use or may not think to do and therefore I thought that I would share some of these experiences and tips with others to help with their day to day work. Currently, my main focus of work is around VMware and Veeam Backup & Replication but hopefully as my tasks progress, I’ll be able to share useful bits of information about other areas of IT as well.

1 thought on “Weekly Snapshot Report PowerCli (BAW8)

Leave a Reply

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