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
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
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
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.
Hi there,
Can you show how you use the script from snapshot size post?
Thank you!
Vitali
PowerCLI Team
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...
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.
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
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.
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
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: ( [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
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
Perfect, working great now. As always, thank you very much!!