Quantcast
Channel: VMware Communities : Document List - vSphere PowerCLI
Viewing all articles
Browse latest Browse all 379

Fast Snapshot Report

$
0
0

We needed a way to identify all machines that had snapshots.  Get-snapshot was far too slow, so I wrote this script to quickly generate a report of all VMs with snapshots more than 2 weeks old.  This script completes in 2.3 seconds when run against 400 VMs.  You will need to insert your own datacenter name.

 

$datacenter = "**datacenter name**"
$outputFile="snapreport.html"
$SnapReport = @()
Get-View -ViewType VirtualMachine -Property Name,Snapshot -SearchRoot(Get-Datacenter $datacenter | get-view).MoRef `

-Filter @{"Snapshot"="VMware.Vim.VirtualMachineSnapshotInfo"} | foreach-object {
    $vmname = $_.Name
    (Get-View -Id $_.MoRef -Property Snapshot).Snapshot.RootSnapshotList | foreach-object {
        If ($_.CreateTime -lt (get-date).adddays(-14)){
            $row = "" | Select-Object VirtualMachine, SnapshotName, SnapshotCreated
            $row.VirtualMachine = $vmname
            $row.SnapshotName = $_.Name
            $row.SnapshotCreated = $_.CreateTime
            $SnapReport += $row
        }
    }
}
$style = "<style>"
$style = $style + "BODY{background-color:white;}"
$style = $style + "TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}"
$style = $style + "TH{border-width: 2px;padding: 5px;border-style: solid;border-color: white;background-color:black;color: white}"
$style = $style + "TD{border-width: 2px;padding: 5px;border-style: solid;border-color: black;background-color:LightCyan;color: black}"
$style = $style + "</style>"
$body = "<H2>Snapshot Report</H2>"
$body = $body + "<H4>Snapshots older than 2 weeks</H4>"


$SnapReport | ConvertTo-HTML -head $style -body $body | out-file $outputFile


Viewing all articles
Browse latest Browse all 379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>