VMware Cloud Community
crosen
Contributor
Contributor
Jump to solution

Gathering snapshot size info takes 10+ hours

I stipped out most of the other information so it is only pulling the VM name, number of snapshots, and total size. However it sstill takes 8-12 hours to complete. Is there any way to speed this up? Thanks.

$report = @()

Get-VM | %{

$vmGuest = $_ | Get-VMGuest

$vm = $_ | Get-View

$row = "" | Select VMName, NoOfSnapshots, AllSnapshotSizeGB

$row.VMname = $_.Name

$row.NoOfSnapshots = (@($_ | Get-Snapshot)).Count

$row.AllSnapshotSizeGB = "{0:N1}" -f (($_ | Get-Snapshot | Measure-Object -Property SizeMB -Sum).Sum/1024)

$report += $row

}

$report | Export-Csv $filename1 -NoTypeInformation -UseCulture

Disconnect-VIServer -Confirm:$False

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Forgot to tell you that.

The script uses a C# structure which allows me to add a variable number of columns for the snapshots.

But once this structure is loaded in your PS environment you can't change it anymore.

Can you stop/start the PowerCLI prompt or whatever PS environment you are running the script from ?

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

The Get-Snapshot cmdlet is indeed quite slow (compared to other cmdlets).

A quick win in your script would be to limit the number of calls to Get-SNapshot.

Something like this would already halve the execution time.

$report = @()
Get-VM | %{
	$vmGuest = $_ | Get-VMGuest
	$vm = $_ | Get-View
	$row = "" | Select VMName, NoOfSnapshots, AllSnapshotSizeGB
	$row.VMname = $_.Name
	$snaps = @($_ | Get-Snapshot)
	$row.NoOfSnapshots = $snaps.Count
	$row.AllSnapshotSizeGB = "{0:N1}" -f (($snaps | Measure-Object -Property SizeMB -Sum).Sum/1024)
	$report += $row
}
$report | Export-Csv $filename1 -NoTypeInformation -UseCulture
Disconnect-VIServer -Confirm:$False

There is also a good post by Dimitar and Vitali on snapshots. See the Snapshot Size post.

And I did a post on snapshot size calculation, which deviates from the standard method. See my yadr – A vdisk reporter post.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
crosen
Contributor
Contributor
Jump to solution

When I use this one (http://blogs.vmware.com/vipowershell/2010/09/snapshot-size.html) it seems to be wrong because a VM with a number of snapshots returned has nothing in the total snapshot size. However, the VMs that do not show a snapshot have a size in the column.

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi there,

Can you show how you use the script from snapshot size post?

Thank you!

Vitali

PowerCLI Team

0 Kudos
crosen
Contributor
Contributor
Jump to solution

This appears to give me total SAN consumption versus just the snapshot size.

lab-svauto10 1 105

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Get-VM | select Name,

@{N="#Snapshots";E={($_ | Get-Snapshot).Count}},

@{N="Snapshot size GB";E={(C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Notes_Fields\TCOMDB_Data\getsnapshotsize-1.ps1 $_ | Measure-Object -Property SizeMB -Sum).Sum}} |`

Export-Csv $filename1 -NoTypeInformation #-UseCulture

Script it calls attached below...

0 Kudos
crosen
Contributor
Contributor
Jump to solution

I downloaded the yadr script and it runs infinitely faster. I'd like to drop label, path, thin, rdm, used, capacity, allocated, and shapshot names. I'd also prefer the total snapshot size, but I can read those in and add them in a Perl script after the fact.

Also, the script seems to stop at 2 snapshots and not the maximum for a given VM.

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi Crosen,

The script from snapshot size post is based on Datastore Browser because it works against API version 2.5 and API version 4.0. This mean that you can use this script against VC 2.5 and ESX 3.5.

Using the datastore browser can be slow operation when you are making a lot of calls for a lot of objects - files/snapshot/etc.

The LucD script, yadr works only agains API version 4.0. There's new property which gives with single call the information about the size of each snapshot disk. Because of that this script is faster.

Now I have two more questions:

1. Can you attach csv report generated from Get-SnapshotSize.ps1 script - in this way we will be able to compare the screen shot, the yadr script output and the output from get-snapshotsize.ps1

2. Is your datastore NFS?

Regards,

Vitali PowerCLI team

0 Kudos
crosen
Contributor
Contributor
Jump to solution

I created a side-by-side comparison of output from the initial script using get-snapshot, the getsnapshotsize-1.ps1, and yadr for a handful of machines.

Luc, copying the script by using the button versus copy/paste, I was then able to run the script and get snapshot info all the way through snapshot N. I'd still like to drop the fields that are not important to me and consolidate snapshot size.

Thanks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Attached a shortened version of yadr.

And it includes a total snapshot size column.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Property 'TotalSnapMB' cannot be found on this object; make sure it exists and

is settable.

At C:\MyDocs\work\Virtualization\VMWare\VMware_Healthcheck\Notes_Fields\TCOMDB_

Data\Yadr-mini.ps1:79 char:14

+ $diskInfo. <<<< TotalSnapMB = ("" -f $totalSnapMB)

+ CategoryInfo : InvalidOperation: (Smiley Happy [], RuntimeException

+ FullyQualifiedErrorId : PropertyAssignmentException

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Forgot to tell you that.

The script uses a C# structure which allows me to add a variable number of columns for the snapshots.

But once this structure is loaded in your PS environment you can't change it anymore.

Can you stop/start the PowerCLI prompt or whatever PS environment you are running the script from ?

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
crosen
Contributor
Contributor
Jump to solution

Perfect, working great now. As always, thank you very much!!

0 Kudos