Help: pwsh command won’t take command-line arguments

Welcome Forums General PowerShell Q&A Help: pwsh command won’t take command-line arguments

Viewing 11 reply threads
  • Author
    Posts
    • #198677
      Participant
      Topics: 1
      Replies: 3
      Points: 22
      Rank: Member

      (cross posted on stack overflow)

      According to pwsh documentation, I should be able to pass command-line arguments but I am getting errors instead (both from a PS prompt and from a CMD prompt):

      > pwsh -NoExit
      -NoExit : The term '-NoExit' is not recognized as the name of a cmdlet, function, script file, or operable program.
      ...
      
      > pwsh -NoLogo
      -NoLogo : The term '-NoLogo' is not recognized as the name of a cmdlet, function, script file, or operable program.
      ...
      
      > pwsh -h
      -h : The term '-h' is not recognized as the name of a cmdlet, function, script file, or operable program.
      ...
      
      > pwsh -Command "Write-host hello"
      -Command : The term '-Command' is not recognized as the name of a cmdlet, function, script file, or operable program.
      ...
      

      But this works:

      > pwsh "Write-host hello"
      hello
      

      My pwsh version is 6.2.3.0

      What is going on???

       

    • #198701
      Participant
      Topics: 4
      Replies: 1906
      Points: 4,250
      Helping Hand
      Rank: Community Hero

      Did you try to run the pwsh executable with its complete path?

    • #198722
      Moderator
      Topics: 3
      Replies: 212
      Points: 1,130
      Helping Hand
      Rank: Community Hero

      Yes, it looks like your installation is broken, please reinstall and check to see if it’s working.

      Also, try using ‘/’ instead of ‘-‘

      > pwsh /nologo

      Thank you.

    • #198740
      Participant
      Topics: 4
      Replies: 1906
      Points: 4,250
      Helping Hand
      Rank: Community Hero

      Also, try using ‘/’ instead of ‘-‘

      Why that? What difference would it make if the executable in front of the argument isn’t found?

    • #198749
      Moderator
      Topics: 3
      Replies: 212
      Points: 1,130
      Helping Hand
      Rank: Community Hero

      Also, try using ‘/’ instead of ‘-‘

      Why that? What difference would it make if the executable in front of the argument isn’t found?

      Yeah I know, you are right, but just in case, that’s it.

    • #198752
      js
      Participant
      Topics: 28
      Replies: 771
      Points: 2,214
      Helping Hand
      Rank: Community Hero

      Are you running the executable or a .bat file?

    • #198788
      Senior Moderator
      Topics: 8
      Replies: 1178
      Points: 4,158
      Helping Hand
      Rank: Community Hero

      what is it showing when you do ?

      pwsh --help
      pwsh /?
      

      It should give the possible options to use with it.

      • This reply was modified 2 months, 1 week ago by kvprasoon. Reason: add more info
    • #199325
      Participant
      Topics: 1
      Replies: 3
      Points: 22
      Rank: Member

      Nope:

      PS> C:\Users\ericj\.dotnet\tools\pwsh.exe --help
      At line:1 char:3
      + --help
      ...
      Unexpected token 'help' in expression or statement.
      
      PS> C:\Users\ericj\.dotnet\tools\pwsh.exe /?
      /? : The term '/?' is not recognized as the name of a cmdlet, function, script file, or operable program.
      
      PS> C:\Users\ericj\.dotnet\tools\pwsh.exe "write-host hello"
      hello
    • #199328
      Participant
      Topics: 1
      Replies: 3
      Points: 22
      Rank: Member

      Uninstalling and reinstalling did not work:

      PS> dotnet tool uninstall --global PowerShell
      Tool 'powershell' (version '6.2.3') was successfully uninstalled.
      PS> pwsh
      pwsh : The term 'pwsh' is not recognized as the name of a cmdlet, function, script file, or operable program.
      
      PS> get-command pwsh
      get-command : The term 'pwsh' is not recognized as the name of a cmdlet, function, script file, or operable program.
      
      PS> dotnet tool install --global PowerShell
      You can invoke the tool using the following command: pwsh
      Tool 'powershell' (version '6.2.3') was successfully installed.
      
      PS> get-command pwsh
      CommandType Name Version Source
      ----------- ---- ------- ------
      Application pwsh.exe 6.2.3.0 C:\Users\ericj\.dotnet\tools\pwsh.exe
      
      PS> pwsh /nologo
      /nologo : The term '/nologo' is not recognized as the name of a cmdlet, function, script file, or operable program.
      
      PS> pwsh /?
      /? : The term '/?' is not recognized as the name of a cmdlet, function, script file, or operable program.
      
      PS> pwsh --help
      Missing expression after unary operator '--'.
      Unexpected token 'help' in expression or statement.
      
      PS> pwsh "write-host hello"
      hello
    • #199334
      js
      Participant
      Topics: 28
      Replies: 771
      Points: 2,214
      Helping Hand
      Rank: Community Hero

      I don’t know what this is. I get powershell core here: https://github.com/PowerShell/PowerShell

    • #199346
      Participant
      Topics: 1
      Replies: 3
      Points: 22
      Rank: Member

      I don’t know what this is. I get powershell core here: https://github.com/PowerShell/PowerShell

      Thanks!  Installing from the .msi on that page fixed my problem.

    • #199424
      Participant
      Topics: 0
      Replies: 2
      Points: 15
      Rank: Member
Viewing 11 reply threads
  • You must be logged in to reply to this topic.