Wednesday, August 10, 2016

VM Snapshot with Datastore Information

VM Snapshot with Datastore Information

Hello Guys

The actual credit goes to couple of guys here who gave me raw of this script.
This is the first script I wrote and improved continuously over the period of time. Every week I saw the script output and seek another opportunity to improve.

Initially this script should be letting me know about the active snapshots in the environment. Later on it was pointed out that Datastore information is missing which is technically the deciding factor to keep or commit the snapshot. Whereas VMware recommends to keep maximum 3 Snapshots for 3 days but he knew this too that infra doesn't run by with recommendations. Anyway, as we all know if datastore free space is anywhere near ZERO, we are doomed so its not about the age. Point accepted and added it as another table in output (because couldn't figure out a way to keep it in single table - dumb me), which addressed the concern but not in a good way. Or should I say difficult to read and understand? To understand the output, you need to review two tables and co-relate them to find out the affected Snapshot and Datastore. And saw another bug as "system.object" instead of Datastore information in few of the cells against couple of VMs. BOOM!

First thing first, I spend some more time on this and fixed two tables output. Though it is providing Datastore information in the Snapshot table (Datastore Table gone now) but next bug needed my attention too. Reason, this was actually happening against the VM's VMDKs connected from multiple Datastore. Script was not ready to handle to such output of any variable. Actually this was the most tricky part in the script which ate most of my time after fixing whole info in single table. At last, I was able to clean this from my plate too.

Then I used this script for 6 months and felt kinda satisfied with the maturity of this script. Practically I was busy in other stuff and couldn't focus on this to find out another improvement. One day I saw an output of more than 100 active Snapshots so you can imagine the length of the email/table. Now it was very irritating to find out the Datastore running with risk.

"Necessity is the mother of invention" - English-language proverb

Eventually I got something I need "highlight the critical". I started working on this again an implemented it. Now script out was appearing exactly like the Sample Output shown below. It highlights the VMName as Red for less than or equals to 25Gig or Yellow for less than or equals to 50Gig Datastore Free Space. Even if there are multiple datastore involved, VMName will be highlighted in case of any datastore having less free space.

Cool? nah! there are so many things you can do with this script and use the ideas used in this script to create new scripts.

VMware is cool but PowerCLI is like cherry on the top.

Anyway, you can use this script to have an email of all the active Snapshots of VMs as body (no attachment). Do remember to personalize vCenter, SMTP Server, Email etc. before running the script. It is perfectly ready to run as Schedule Task without storing your password in plain text (Security is not breached). Hope you like it and feel free to share and like it.





Sample Output

VMSnapShotReport
SnapshotReport

No comments:

Post a Comment