Well, i have a script that generates what you want. But i use a function which shows the snapshots. You can easily call the function passing the Vcenter connection as parameter Example: $Repo...
See more...
Well, i have a script that generates what you want. But i use a function which shows the snapshots. You can easily call the function passing the Vcenter connection as parameter Example: $Report = Get-Snaps (connect-viserver "yourServer") Warn me if you want some help modifying it.
function Get-Snaps(){
param($currentVC)
#Filter only Vms which contains Snapshots
Write-Host "`t Generating Report from Server: $($currentVC.name)"
#Filter Templates and non Snapshotteds Vms
$vmsWithSnaps = Get-view -viewType VirtualMachine -Property Name,Config.Template,Snapshot -Server $currentVC -Filter @{'Config.Template'='False'}|where{$_.snapshot -ne $null}
if($vmsWithSnaps){
try{
foreach($vm in $vmswithSnaps){
$currVM = $vm|Get-VIObjectByVIView
if($currVM){
Write-Host "`t`tSnapshots found Here: $($currVM.Name)"
$VMsnaps = $currVM | Get-Snapshot
$tempReport = $VMsnaps | Select VM,@{N="Vcenter";E={$currentVC.Name}},@{N="Cluster";E={($currVM|get-cluster|select Name).Name}},@{N="Host";E={$currVM.Vmhost.Name}},Name,@{N="PowerState";E={$currVM.PowerState}},Description,Created,SizeGB,Datastores,FileNames,UserName
#Get Snapshot Files
$snapFiles = Get-HardDisk -Snapshot $VMsnaps
#Get who created it
$SnapshotEvents = Get-VIEvent -Entity $currVM -type info -MaxSamples 1000 | Where {$_.FullFormattedMessage.contains("Create virtual machine snapshot")}
try{
$user = $SnapshotEvents[0].UserName
}catch [System.Exception] {
$user = $SnapshotEvents.UserName
}
$tempReport|%{
$_.SizeGB = "{0:N2}" -f $tempReport.SizeGB
$_.UserName = $user
$_.Datastores = ([String]($snapFiles|%{$_.Filename.split("]")[0].split("[")[1]}| select -Unique)).replace(" ",",")
$_.FileNames = ([String]($snapFiles|%{($_.FileName).replace(" ","")})).replace(" ",",")
}
$tempReport
}
}
}catch{
#do nothing, let it go
}
}else{
$tempReport = ""| Select VM,PowerState,Vcenter,Name,Description,Created,SizeGB,UserName
$tempReport.VM = "No Snapshots found on $($currentVC.Name)"
$tempReport
}
}