Yesterday, alanrenouf asked the following question on the VMware Community VI Toolkit forums:

Is there a way (preferably a one-liner) to get a list of vm’s and the number of snapshots per vm?

Here’s a script that will get that info:

$VC = Connect-VIServer $VCServerName
$vms = Get-VM
$myCol = @()
ForEach ($vm in $vms)
{
  $snapshots = Get-Snapshot -VM $vm
  $myObj = "" | Select-Object VM, NumSnapshots
  $myObj.VM = $vm.name
  $myObj.NumSnapshots = ($snapshots | measure-object).count
  $myCol += $myObj
}
$myCol | Where-Object{$_.NumSnapshots -gt 0} | Sort-Object VM | Format-Table -AutoSize

And here’s a one-liner that does the same thing: 

Get-VM |
  Where{(Get-SnapShot -VM $_ | Measure-Object).Count -gt 0} |
  Format-Table Name, `
  @{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}

»crosslinked«

Related posts:

  1. Calculate vSphere 5 Licenses with Powershell (UPDATED)
  2. Remove vmware memory limits with Powershell

  3 Responses to “Powershell Oneliner #4”

  1. This was a great help, thanks very much !

    Alan

    http://teckinfo.blogspot.com/

  2. [...] There are a few sample scripts that you can use. You can find them at the following URLS: http://www.peetersonline.nl/index.php/vmware/powershell-oneliner-4/ [...]

 Leave a Reply

(required)

(required)

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> <pre lang="" line="" escaped="" highlight="">

   
© 2012 PeetersOnline Suffusion theme by Sayontan Sinha