Most of the below script for listing snapshots was passed to me ( i made some small modifications) and it works great except that it will not list the original creator of the snapshot but rather the creator of the latest snapshot even if it doesn't exist, vDP snapshots for example. I believe it's how the Get-VIEvents is being called instead of getting the snapshot creator from the get-snapshot command.
Anyone able to point me in the right direction or use another method of finding snapshot creator?
thanks.
$myVMs = Get-VM
$VMsWithSnaps = @()
foreach ($vm in $myVMs) {
$vmView = $vm | Get-View
if ($vmView.snapshot -ne $null) {
$snapsize = get-vm $vm | get-snapshot | select @{N="SizeMB";E={[Math]::Round($_.SizeMb)}}
$SnapshotEvents = Get-VIEvent -Entity $vm -type info -MaxSamples 1000 | Where {
$_.FullFormattedMessage.contains("Create virtual machine snapshot")}
try {
$user = $SnapshotEvents[0].UserName
$time = $SnapshotEvents[0].CreatedTime
} catch [System.Exception] {
$user = $SnapshotEvents.UserName
$time = $SnapshotEvents.CreatedTime
}
$VMInfo = “” | Select "VM","CreationDate","User","SizeMb"
$VMInfo."VM" = $vm.Name
$VMInfo."CreationDate" = $time
$VMInfo."User" = $user
$VMInfo."SizeMb" = $snapsize.SizeMb
$VMsWithSnaps += $VMInfo
}
}
$VMsWithSnaps | Sort CreationDate | ft -auto
after searching around on google, original script looks to have come from:
Find virtual machine snapshots with PowerCLI | Notes from a Sysadmin