Find commands with parameter names

Welcome Forums General PowerShell Q&A Find commands with parameter names

Viewing 11 reply threads
  • Author
    Posts
    • #101089
      Participant
      Topics: 8
      Replies: 16
      Points: 74
      Rank: Member

      Hello,
      Trying to find the list of cmdlets which has Port parameter defined. I am expecting Test-NetConnection cmdlet in the result pane after executing

      But, I see

        Microsoft.PowerShell.Core
        Microsoft.PowerShell.Management

      module cmdlets.

      Am I doing anything wrong here? Appreciate your help!

      Thanks

    • #101091
      Participant
      Topics: 6
      Replies: 120
      Points: 128
      Helping Hand
      Rank: Participant

      Hi Harsha,

      What version are you using? I’ve tried in V5.1 and 6 and get the following.

      Without -all

      And with -all I get

      • #101101
        Participant
        Topics: 8
        Replies: 16
        Points: 74
        Rank: Member

        Hello Alex,
        It is 5.1 Version on Windows 2012 R2. My results are similar to yours. None of them retrieved the Test-NetConnection cmdlet even though I have NetTCPIP module installed. It is showing only after importing the module into current session.

        Thanks

    • #101095
      Participant
      Topics: 2
      Replies: 1014
      Points: 2,105
      Helping Hand
      Rank: Community Hero

      Here is a little snippet I pulled together and keep around for such search and find efforts.
      Maybe more than you need at this point, but should show you what you can do.

      • #101151
        Participant
        Topics: 8
        Replies: 16
        Points: 74
        Rank: Member

        Thanks for sharing this snippet.It is so useful for new-comers like me.

    • #101113
      Jon
      Participant
      Topics: 13
      Replies: 226
      Points: 174
      Helping Hand
      Rank: Participant

      Working as designed, per the documentation

      -ParameterName
      Specifies an array of parameter names. This cmdlet gets commands in the session that have the specified parameters. Enter parameter names or parameter aliases. Wildcard characters are supported.

    • #101154
      Participant
      Topics: 8
      Replies: 16
      Points: 74
      Rank: Member

      Jon,
      Thanks for pointing that. So, I believe the discoverability of commands with required parameters looks quite hard then – IMO (For starters atleast). Ideally, I should import all modules (most often used) into the session and do the search- I guess

    • #101202
      js
      Participant
      Topics: 32
      Replies: 848
      Points: 2,729
      Helping Hand
      Rank: Community Hero

      Hmm, get-command returns a .parameters property, but it’s a dictionary.

      Hmm, work in progress. Just need the original command in there.

    • #101248
      Participant
      Topics: 6
      Replies: 667
      Points: 97
      Helping Hand
      Rank: Member
      • #101251
        js
        Participant
        Topics: 32
        Replies: 848
        Points: 2,729
        Helping Hand
        Rank: Community Hero

        Hah, you beat me. Or

    • #101259
      js
      Participant
      Topics: 32
      Replies: 848
      Points: 2,729
      Helping Hand
      Rank: Community Hero

      A weird thing is doing something like “get-command test-connection” will load the module that it’s in (Microsoft.PowerShell.Management). (This is 6.1PR2 on my mac.)

      And that leads to another way. Just “get-command | get-command” won’t work.

      Ah, putting /pre on a new line creates a blank line in a code block.

      More mischief with passing multiple parameters over the pipe when one parameter can be passed byvalue. Powershell attempts the useless converting of a hash-table into a string for the name parameter.

    • #101305
      Participant
      Topics: 6
      Replies: 667
      Points: 97
      Helping Hand
      Rank: Member

      So Get-command by itself sees all the command/functions available, but does not load the necessary modules if they are currently unloaded to see the parameters.

      IE.

      But passing the command as a parameter causes get-command to load the necessary module to see the parameters

      IE.

      That is why piping get-command into a select-object and then back to get-command could work. You just need a slight modification to your command to expand the name property so that the second get command is just receiving the name value.

      IE.

    • #101320
      js
      Participant
      Topics: 32
      Replies: 848
      Points: 2,729
      Helping Hand
      Rank: Community Hero

      This actually works fine:

    • #101361
      Participant
      Topics: 6
      Replies: 667
      Points: 97
      Helping Hand
      Rank: Member

      So it does. Nice. 🙂

    • #104675
      Participant
      Topics: 8
      Replies: 16
      Points: 74
      Rank: Member

      Thanks everyone for putting your thoughts and helping out..

Viewing 11 reply threads
  • The topic ‘Find commands with parameter names’ is closed to new replies.