vSphere plugin to show snapshots

I've mentioned before that making vSphere plugins is a bit hit and miss...it seems that things have progressed some what since I last attempted this and in vSphere 5.1 things are much much easier!

I wrote some powershell which put a html file containing all snapshots in the environment into the root of an IIS website.  The website was set to use this page as the default.  A scheduled task runs this each night.  Then I added a plugin to vSphere referencing the website and now we are able to see all the snapshots currently in use!

Hoorah!

Here's the powershell (we use Veeam and I've made it so that the Veeam replicas are not shown)

# Powershell to show current running snapshots

# open the vSphere powershell
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

# Connect to VCS-002
$server = Connect-VIServer GBR-LON-VCS-002.EDFMAN.NET

# Now Output all the VMs which have snapshots - ignoring those Veeam replicas
$data = Get-VM | Get-Snapshot | ?{$_.Name -notmatch "Restore Point "}| select VM, Name, Created | Sort Created

# Now stick this into HTML
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{font-family:Arial, sans-serif;border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"

$data | ConvertTo-Html -Head $a | Out-File C:\Websites\vsphere\vmware_snapshots.htm

# Uncomment the next line to see a rendition of the page
# Invoke-Expression C:\Scripts\vmware_snapshots.htm

Disconnect-VIServer $server -Force -Confirm:$false

And here is the plugin .xml just make a folder called Snapshots in and put it inside

<vSphere installation directory>\VMware\Infrastructure\Virtual Infrastructure Client\Plugins

 <scriptConfiguration version="1.0.0">
  <key>Snapshots</key>
  <description>Current snapshots</description>
  <vendor>Your Company</vendor>
- <view parent="Inventory.Admin">
  <title locale="en">Snapshots</title>
  <url>http://your-url</url>
  </view>
  </scriptConfiguration>

This xml file will put a shortcut on the home screen in vSphere.  Enjoy.







Comments

Popular posts from this blog

PXE booting, MDT and 802.1x

Intune installation requires a wire...or does it?

Powershell VPN connections - PEAP with MSCHAPv2