VMware Cloud Community
alexander19
Contributor
Contributor

Snapshot report

Hi,

I have few methods to report some snapshots from my enviroment:

First method:

Get-VM | %{$vm = $_.Name ; $_ | Get-Snapshot | Where { $_.Name -like "auto-*"} | Measure-Object | %{write-host $vm $_.Count}}

VM Name      Snapshots with "auto" in name

VM1                                 2

VM2                                1

With this method I can get what I want: VM name and number of snapshots with "auto" word found in name but exporting to HTML only generate a blank file

Second method:

$ss = Get-vm | Get-Snapshot
#$ss | Select-Object vm, name, description, powerstate | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report</H2>"| Out-File $filename
$ss | Select-Object vm, name, description | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report</H2>"| Out-File $filename

$ss = Get-vm | Get-Snapshot

#$ss | Select-Object vm, name, description, powerstate | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report</H2>"| Out-File $filename

 

$ss | Select-Object vm, name, description | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report</H2>"| Out-File $filename

VM Name          Snapshot name

VM1                    snapshot1

VM1                   snapshot2

 

VM2                  snapshot2

VM2                 snapshot3

This method is working but I'm able to get only VM name on one column and each snapshot with name from each VM.

 

I've already tried all kind of tricks to generate a report with VM name on one column and number of snapshots with "auto" in name but none of this are working.

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Not sure I understand what you want in the report.

If you only want the name of the VM and the number of snapshots with auto in the name, the first snippet is doing that.


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

Reply
0 Kudos
LucD
Leadership
Leadership

Or do you mean like this?

Get-VM |

Select Name,

   @{N='AutoSnap#';E={(Get-SNapshot -VM $_ | where{$_.Name -match 'auto-'}).Count}}}


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

Reply
0 Kudos
alexander19
Contributor
Contributor

I'm able to get the resul on powershell but when I try to export this results on html  I get a blank file
Reply
0 Kudos
LucD
Leadership
Leadership

Try like this

Get-VM |

Select Name,

   @{N='AutoSnap#';E={(Get-SNapshot -VM $_ | where{$_.Name -match 'auto-'}).Count}} |

ConvertTo-Html | Out-String | Set-Content -Path .\report.html


Invoke-Item -Path .\report.html


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

Reply
0 Kudos
alexander19
Contributor
Contributor

As always save the situation, thank you!
Reply
0 Kudos