Finding Cmdlets With a Given Parameter

by Aug 17, 2010

Finding cmdlets by name is easy:

Get-Command *service* -commandType Cmdlet

But how can you list all cmdlets that support a given parameter? If you’d like to see all cmdlets with a -List parameter?

The easiest way is to use Get-Help with the parameter -parameter:

Get-Help * -parameter list

Or, you can use Get-Command and filter the result by parameter. You’ll need a custom filter to accomplish this:

filter Contains-Parameter {
param($name)
$number = @($_ | % { $_.ParameterSets | % { $_.Parameters | ? { $_.Name -eq $name}}}).Count
if ($number -gt 0) {
$_
}
}

This filter allows only those to pass the pipeline that supports the given parameter. Here is how you use the filter:

Get-Command | Contains-Parameter 'list'

Twitter This Tip! ReTweet this Tip!