Automation

 View Only
  • 1.  Find last time a Snapshot has been used

    Posted Jul 12, 2021 06:59 AM

    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



  • 2.  RE: Find last time a Snapshot has been used
    Best Answer

    Posted Jul 12, 2021 07:25 AM

    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}}
    }
    

     



  • 3.  RE: Find last time a Snapshot has been used

    Posted Jul 12, 2021 07:30 AM

    Hi ,

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