Powershell Oneliner #4
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}}
3 Responses to Powershell Oneliner #4
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





This was a great help, thanks very much !
Alan
http://teckinfo.blogspot.com/
[...] http://www.peetersonline.nl/index.php/vmware/powershell-oneliner-4/ http://communities.vmware.com/docs/DOC-6980 [...]
[...] 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/ [...]