I wrote the code below to create a table for a snapshot report. It's not the best in powershell coding techniques so I was hoping someone could offer suggestions on improving speed and shorten the number of lines needed. I added the $Snapshot.created filter because it seems to run faster with the that. Right now I can also only get the report to run to by piping it to a file using the command line below. I'd like to be able to use some cmdlet to get the output. I also thought about using XML to display the data in HTML but I'm not familiar with XML.
Any help on improving this would be greatly appreciated.
Run it using : ./listsnapshotreport.ps1 | report.htm
======== ListSnapshotreport.ps1 ========
$null = Get-VIServer "
Have you had a chance to check out the ConverTo-Html cmdlet?
NAME ConvertTo-Html SYNOPSIS Creates an HTML page that represents an object or a set of objects. SYNTAX ConvertTo-Html [-inputObject <psobject>] [[-property] <Object>] [-body <string>] [-h ead <string>] [-title <string>] [<CommonParameters>] DETAILED DESCRIPTION The ConvertTo-HTML cmdlet creates an HTML page that represents one or more objects. The cmdlet returns a complete HTML page with the input objects in an HTML table on the page. The object's properties are column headings and the property values are listed in the t able rows.
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Hope this helps.
$VC = "server.domain.ext"
Write-Host "Connecting to VC server $VC ..."
$connectingVC = Get-VIServer $VC
Write-Host "Locating all virtual servers"
$vms = Get-VM
$myCol = @()
ForEach ($vm in $vms)
Write-Progress "Searching for snapshots" "Percent complete" +-PercentComplete +(100*$i/$vms.Length)
$snapshots = Get-SnapShot -VM $vm
ForEach ($snapshot in $snapshots)
$myObj = "" | Select-Object VM, Snapshot, Created
$myObj.VM = $vm.name
$myObj.Snapshot = $snapshot.name
$myObj.Created = $snapshot.created
$myCol += $myObj
$myCol | Sort-Object VM | Format-Table -AutoSize