function to list all VMs with Snapshots

Using the PowerGUI, you can list all snapshots, but unfortunately, it doesn’t list the parent VM.

I wrote a quick little function to search all VMs that have snapshots and list them.

function get-snaps{
    $vms = get-vm | sort name
    $vmsnaps = @()
    foreach($vm in $vms){
    	$snap = Get-Snapshot $vm
    	if($snap){
		  $vmsnaps += $vm
		  write-host -fore green `n `t $vm
		  $snapshots = Get-Snapshot $vm
		  foreach ($snapshot in $snapshots){
			write-host "name: " $snapshot.name " size: " ($snapshot.sizemb/1024)
    		}
    	}
    }
}

get-snaps

Just save that into a .ps1 file and run it. Make sure you’re connected to a vCenter or it won’t work.

Expected output is like this:

         Server1
name:  Description  size:  0.07853515625

         Server2
name:  Description    size:  3.79728515625

         Server3
name:  Consolidate Helper- 0  size:  1.6565625

         Server4
name:  Consolidate Helper- 0  size:  73.45369140625

         Server5
name:  Consolidate Helper- 0  size:  53.60998046875

         ARPDBW0025202
name:  Description    size:  0.01630859375
This entry was posted in Scripts, Virtualization and tagged , , , by Luke. Bookmark the permalink.

About Luke

Hello! My name is Luke Huckaba and I'm an addict. My drug of choice is technology and I'm far from sober. I'm currently a Systems Specialist and specialize in anything Windows-related, Dell server hardware, and Virtualization using VMWare products. In my spare time, when not toying with the above mentioned items, I can be found riding my motorcycle, working on cars, and attempting to play softball. Feel free to shoot me an e-mail with any questions you may have.

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=""> <strike> <strong>