«

»

Mar 01

Quick PowerCLI to Get SnapShots and Size

Just a quick VMware PowerCLI one liner to display the number of snapshots for each VM and the total size in MB of the snapshots for each VM.

Get-VM | Format-Table Name, @{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}, @{Label="TotalSnapShotSizeMB";Expression={(Get-Snapshot -VM $_ | Measure-Object -Sum SizeMB).Sum}}

The cmdlet Get-VM gets all the VMs in the environment. The Get-Snapshot cmdlet counts the number of snapshots and then provides a sum of the total size in MB. Change SizeMB to SizeGB to get the sum of snapshot size in GB.

snapshot-powercli

About the author

vHersey

Hersey Cartwright is an IT professional with extensive experience designing, implementing, managing, and supporting technologies that improve business processes. Hersey is Solutions Architect for SimpliVity covering Virginia, Washington DC, and Maryland. He holds the VMware Certified Design Expert (VCDX-DV #128) certification. Hersey actively participates in the VMware community and was awarded the VMware vExpert title in 2016, 2015, 2014, 2013, and 2012. He enjoys working with, teaching, and writing about virtualization and other data center technologies. Follow Hersey on Twitter @herseyc

2 comments

  1. marco

    Hi vHersey

    great post!
    I don’t like all these decimal and I would like to round the value using [math]::round function but I couldn’t make it work

    Do you have any suggestion?

  2. Roy Hutton

    Appreciate it but – not a fan of the above command myself, it doesn’t even autosize the table in the output, why not:

    Get-Snapshot * | Select-Object -Property Name, SizeGB, VM, PowerState, Children | Sort-Object -Property sizeGB -Descending | ft -AutoSize

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

19 + eighteen =