PowerShell – Finding all commands with a specific parameter

Last week I was giving a PowerShell workshop and asked my students to find all cmdlets with a specific parameter, in this case the “-Like” parameter.

There’s a bunch of ways to do this, but the easiest way we found was the following:

Get-Command | Where-Object { $_.Definition –like “*-list*” }

image

Now, this will also find commands with a parameter such as “-ArgumentList”… so if we want to exclude those from the result:

Get-Command | Where-Object { ( $_.Definition –like “*-list*” ) –and ( $_.Definition –notlike “*-ArgumentList*” ) }

image

4 comments

  1. Walid2mi says:

    #  find all command with ‘list’ parameter
    #> get-help * -param list

  2. Jeff Wouters says:

    Hi Walid2mi,
    Although the command you’ve provided is a lot shorter and easier to remember, it also takes quite a bit longer to execute…
    Jeff.

  3. Walid2mi says:

    hi jeff,

    this is my test:

    PS> measure-command { get-help * -param list }
    –> TotalMilliseconds : 4778,5757

    PS> measure-command { Get-Command | Where-Object { $_.Definition –like “*-list*” } }
    –> TotalMilliseconds : 893,1512

    PS> measure-command { help * -param list }
    -> TotalMilliseconds : 403,8105

  4. Jeff Wouters says:

    So, for finding all commands with one specific parameter,the “help * -param list” is easiest and fastest to use.

Leave a Reply

Your email address will not be published. Required fields are marked *