03 Apr 2012 @ 6:33 PM 

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

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 25 Apr 2012 @ 08:31 PM

EmailPermalink
Tags
Categories: PowerShell


  • http://walid-toumi.blogspot.com/ Walid2mi

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

  • http://www.jeffwouters.nl Jeff Wouters

    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.

  • http://walid-toumi.blogspot.com/ Walid2mi

    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

  • http://www.jeffwouters.nl Jeff Wouters

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


 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 252
  • Comments » 432
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.