PowerTip: Find Only PowerShell Cmdlets that Use “Get”

Summary: Find only Windows PowerShell cmdlets that use the verb “get.”

Hey, Scripting Guy! Question How can I find cmdlets in Windows PowerShell that use the verb “get” when the parameters –Verb and –CommandType are exclusive?

Hey, Scripting Guy! Answer Use Get-Command to find the –CommandType of the cmdlet, pipe the results to Where-Object,
          and look for a verb equal to Get:

get-command -CommandType cmdlet | where verb -eq get

Comments (7)

  1. mredwilson says:

    @David Wyatt yes, it is interesting, and in fact I was basically surprised when I found this out. It would be possible to create a proxy function and add to the command if this is something one does all the time. I, myself, wrote a function I have in my profile that allows me to do more granular searching.

  2. David Wyatt says:

    It's interesting that the -Verb and -Noun parameters aren't allowed with CommandType, etc.  The parameter set names for Get-Command are "CmdletSet" (-Verb / -Noun), and "AllCommandSet" (-Name / -CommandType).  It seems like that would imply that when you use -Verb and -Noun, you should be getting back only Cmdlets, not functions / etc.

    I wonder if the design / functionality has changed (perhaps when Advanced Functions were added in PowerShell 2.0), allowing -Verb and -Noun to provide information about functions in addition to Cmdlets.  If that's the case, maybe they should do away with these parameter sets and just allow you to combine the parameters however you like.

  3. Tarqiue Noorain says:

    other way :

    Get-Command -CommandType cmdlet get*

  4. Krunch {The Commenter formerly known as K} says:

    Simpler is better

    gcm (get-command) has a variable '-verb' and '-noun'

    gcm -verb get*

  5. Krunch {The Commenter formerly known as K} says:

    I incorrectly stated variable, These are parameters. Excuse my stupidity

  6. MockMyBeret says:

    Good scripting technique always says to filter smaller groups.

    Get-Command -verb get

    will most likely return less items to filter than

    Get-Command -CommandType cmdlet

    Several tests on some of my boxes show that having the command filter by verb instead of commandtype and then filtering with where-object is twice as fast.

  7. Ed Wilson says:

    @Tarqiue Noorain very nice. Great solution.

    @Krunch (former K) and @MockMyBeret Both of your proposed solutions do not work on Windows 8 and Windows 8.1 because they will also return a large (very large) number of functions AS WELL AS cmdlets.

Skip to main content