VMware Cloud Community
Tomtom90
Contributor
Contributor
Jump to solution

Find last time a Snapshot has been used

Hi everyone,

I was wondering, is there a way to get the date of last use for a snapshot?
Meaning the date of last reversion, not the date of creation.

Thanks in advance

Tom

Labels (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can get the latest 'Revert to snapshot' via Get-ViEvent.
How far you can go back depends on how long you keep events in your environment.
Update the Start parameter accordingly.

This gives the full list, to get this for a specific VM, add a Where-clause.

Get-Vievent -Start (Get-Date).AddDays(-7) -Maxsamples ([int]::MaxValue) |
Where-Object { $_ -is [VMware.Vim.EventEx] -and $_.EventTypeId -eq 'com.vmware.vc.vm.VmStateRevertedToSnapshot' } |
Group-Object -Property ObjectName -PipelineVariable vm |
ForEach-Object -Process {
  $_.group | Sort-Object -Property CreatedTime -Descending |
  Select -First 1 |
  Select @{N='VM';E={$vm.Name}},
    CreatedTime,
    EventTypeId,
    @{N='Snapshot';E={$_.Arguments.where({$_.Key -eq 'snapshotName'}).Value}}
}

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

You can get the latest 'Revert to snapshot' via Get-ViEvent.
How far you can go back depends on how long you keep events in your environment.
Update the Start parameter accordingly.

This gives the full list, to get this for a specific VM, add a Where-clause.

Get-Vievent -Start (Get-Date).AddDays(-7) -Maxsamples ([int]::MaxValue) |
Where-Object { $_ -is [VMware.Vim.EventEx] -and $_.EventTypeId -eq 'com.vmware.vc.vm.VmStateRevertedToSnapshot' } |
Group-Object -Property ObjectName -PipelineVariable vm |
ForEach-Object -Process {
  $_.group | Sort-Object -Property CreatedTime -Descending |
  Select -First 1 |
  Select @{N='VM';E={$vm.Name}},
    CreatedTime,
    EventTypeId,
    @{N='Snapshot';E={$_.Arguments.where({$_.Key -eq 'snapshotName'}).Value}}
}

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Tomtom90
Contributor
Contributor
Jump to solution

Hi @LucD,

thanks for your quick response. I was afraid that it would be only via the events.

Reply
0 Kudos