VMware Cloud Community
crosen
Contributor
Contributor

Can you list the number of reverts per snapshot per VM?

VM Name          Snapshot Name          Times Reverted (30 days)

vm001               Base install                    4

Thanks.

Reply
0 Kudos
19 Replies
RvdNieuwendijk
Leadership
Leadership

I am not able to get the number of snapshot reverts per snapshot per vm. But I am able to get the number of snapshot reverts per virtual machine. I hope this will help a little.

Get-VIEvent -Start (Get-Date).AddDays(-30) -Types Info | `
Where-Object {$_.FullFormattedMessage -like "Task: Revert*"} | `
Select-Object -ExpandProperty Vm | `
Select-Object -Property Name | `
Group-Object -Property Name | `
Select-Object -Property Name,Count

Regards, Robert

The Where-Object line in the script changed because of Luc's remark about missing some events.

Message was edited by: RvdNieuwendijk

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
LucD
Leadership
Leadership

You can find the snapshot reverts in the TaskEvent entries.

But it looks as if these events do not contain the name of the snapshot to which the guest was reverted.

$report = @()

Get-VIEvent -Start (Get-Date).AddDays(-1) | `
    where {$_.GetType().Name -eq "TaskEvent" -and $_.FullFormattedMessage -like "Task: Revert*"} | %{         $row = "" | Select VM,Date         $row.VM = $_.Vm.Name         $row.Date = $_.CreatedTime         $report += $row} $report


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

Reply
0 Kudos
LucD
Leadership
Leadership

The message can also say "Task: Revert to current snapshot".

You will be missing those I'\m afraid.


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

Reply
0 Kudos
crosen
Contributor
Contributor

The string starting:
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Snapshots\snapshot-f
requency-v2.ps1:12 char:138
+ Get-VIEvent -Start (Get-Date).AddDays(-1) | `where {$_.GetType().Name -eq "Ta
skEvent" -and $_.FullFormattedMessage -like "Task: Revert*"} <<<< ' | %{
is missing the terminator: '.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Snapshots\snapshot-f
requency-v2.ps1:20 char:36
+ Disconnect-VIServer -Confirm:$False <<<<
    + CategoryInfo          : ParserError: ( | %{
        ...-Confirm:$False:String) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

Reply
0 Kudos
crosen
Contributor
Contributor

This returned zero results, but I know that is not correct.  

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

It looks like you have put the line beginning with Get-VIEvent and the line beginning with Where on one line. Then you should remove the backquote `. The backquote is used to split a PowerShell command over two lines. If you revert it to one line the backquote should be removed.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
LucD
Leadership
Leadership

The new forum SW seems to have swallowed a CR-LF.

I corrected the code, can you try again ?


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

Reply
0 Kudos
crosen
Contributor
Contributor

The script is running now, but not sure if the data is accurate.  This specific vCenter has over 700 VMs and running the script for the past 30 days resulted in two "reverts".  Everyone has this access so I can't believe that is it.  

Reply
0 Kudos
continuum
Immortal
Immortal

I seriously doubt that you can find out the number of reverts in a reliable way other then inspecting ALL old vmware.logs of that VM.

Guessing by the usual naming convention or something like that would be very unreliable


________________________________________________
Do you need support with a VMFS recovery problem ? - send a message via skype "sanbarrow"
I do not support Workstation 16 at this time ...

Reply
0 Kudos
LucD
Leadership
Leadership

Found the cause, the Get-VIEvent cmdlet even when you use it with the -Start parameter only returns 100 events.

If you add the -MaxSamples parameter with a huge number it will return all your reverts.

$report = @()

Get-VIEvent -Start (Get-Date).AddDays(-30) -MaxSamples 99999  | `
    where {$_.GetType().Name -eq "TaskEvent" -and $_.FullFormattedMessage -like "Task: Revert*"} | %{         $row = "" | Select VM,Date         $row.VM = $_.Vm.Name         $row.Date = $_.CreatedTime         $report += $row} $report


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

Reply
0 Kudos
LucD
Leadership
Leadership

Note that the script will run for a long time !


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

Reply
0 Kudos
crosen
Contributor
Contributor

Then something is wrong because it came back in only a few minutes.

Reply
0 Kudos
LucD
Leadership
Leadership

Did you get more than 2 reverts now ?

You can run the following, that way you are sure that you have at least events for each day.

Get-VIEvent -Start (Get-Date).AddDays(-30) -MaxSamples 99999 | `
    Group-Object -Property {$_.CreatedTime.Date}

And you can do the next script that will show how many Revert tasks you have per day

Get-VIEvent -Start (Get-Date).AddDays(-30) -MaxSamples 99999 | `
    where {$_.GetType().Name -eq "TaskEvent" -and $_.FullFormattedMessage -like "Task: Revert*"} | `
    Group-Object -Property {$_.CreatedTime.Date}

You can of course be running this on a super-fast vCenter 😉


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

Reply
0 Kudos
crosen
Contributor
Contributor

1 - there are a lot more showing up here in the total counted that are not showing up from the original script.

2 - it only went back to 12/8.

Thanks.

Name                       Port                       User
----                       ----                       ----
rtpvcell03                 443                        crosen

Values : {12/15/2010 12:00:00 AM}
Count  : 74
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/15/2010 12:00:00 AM


Values : {12/14/2010 12:00:00 AM}
Count  : 59
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/14/2010 12:00:00 AM


Values : {12/13/2010 12:00:00 AM}
Count  : 37
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/13/2010 12:00:00 AM


Values : {12/12/2010 12:00:00 AM}
Count  : 2
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent}
Name   : 12/12/2010 12:00:00 AM


Values : {12/11/2010 12:00:00 AM}
Count  : 2
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent}
Name   : 12/11/2010 12:00:00 AM


Values : {12/10/2010 12:00:00 AM}
Count  : 64
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/10/2010 12:00:00 AM


Values : {12/9/2010 12:00:00 AM}
Count  : 56
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/9/2010 12:00:00 AM


Values : {12/8/2010 12:00:00 AM}
Count  : 34
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/8/2010 12:00:00 AM

[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI>

Reply
0 Kudos
LucD
Leadership
Leadership

1. There are more showing up in the 2nd script ? The one that filters on the eventtype and task name ?

2. My original post had AddDays(-7). That explains the timerange. Changed it to AddDays(-30).


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

Reply
0 Kudos
crosen
Contributor
Contributor

Get-VIEvent -Start (Get-Date).AddDays(-30) -MaxSamples 99999 | where {$_.GetType().Name -eq "TaskEvent" -and $_.FullFormattedMessage -like "Task: Revert*"} | Group-Object -Property {$_.CreatedTime.Date}

results in...

Values : {12/15/2010 12:00:00 AM}
Count  : 74
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/15/2010 12:00:00 AM


Values : {12/14/2010 12:00:00 AM}
Count  : 59
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/14/2010 12:00:00 AM


Values : {12/13/2010 12:00:00 AM}
Count  : 37
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/13/2010 12:00:00 AM


Values : {12/12/2010 12:00:00 AM}
Count  : 2
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent}
Name   : 12/12/2010 12:00:00 AM


Values : {12/11/2010 12:00:00 AM}
Count  : 2
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent}
Name   : 12/11/2010 12:00:00 AM


Values : {12/10/2010 12:00:00 AM}
Count  : 64
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/10/2010 12:00:00 AM


Values : {12/9/2010 12:00:00 AM}
Count  : 56
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/9/2010 12:00:00 AM


Values : {12/8/2010 12:00:00 AM}
Count  : 34
Group  : {VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMware.Vim.TaskEvent, VMw
         are.Vim.TaskEvent...}
Name   : 12/8/2010 12:00:00 AM

################################################################

This...

Get-VIEvent -Start (Get-Date).AddDays(-30) | where {$_.GetType().Name -eq "TaskEvent" -and $_.FullFormattedMessage -like "Task: Revert*"} | %{
        $row = "" | Select VM,Date
        $row.VM = $_.Vm.Name
        $row.Date = $_.CreatedTime
        $report += $row}
$report

results in...

Name                       Port                       User
----                       ----                       ----
rtpvcell03                 443                        crosen

Reply
0 Kudos
LucD
Leadership
Leadership

You didn't add the -MaxSamples parameter on the 2nd one.

That way you only the last 100 events.


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

Reply
0 Kudos
crosen
Contributor
Contributor

Added, so script is this...

Get-VIEvent -Start (Get-Date).AddDays(-30) -MaxSamples 99999 | where {$_.GetType().Name -eq "TaskEvent" -and $_.FullFormattedMessage -like "Task: Revert*"} | %{
        $row = "" | Select VM,Date
        $row.VM = $_.Vm.Name
        $row.Date = $_.CreatedTime
        $report += $row}
$report

Results in a bunch of this...

Method invocation failed because [System.Management.Automation.PSObject] doesn'
t contain a method named 'op_Addition'.
At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Snapshots\snapshot-f
requency-v2.ps1:17 char:19
+         $report += <<<<  $row}
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], Runti
   meException
    + FullyQualifiedErrorId : MethodNotFound

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

You are missing the first line of the script. The script should start with:

$report = @()

This initialized $report as an empty array.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos