function to list all VMs with Snapshots

Written September 12th, 2011 by
Categories: Scripts, Virtualization
No Comments »

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

Server6
name: asdf size: 0.01630859375

Tags: , , ,

// // // //

Leave a reply

 

Designed by ThepHuck
Wordpress Themes
Scroll to Top