2

I have just installed the open-source version of PowerShell for Linux on Arch Linux using the powershell-git package from AUR. When I try PowerShell's -Version functionality, I get the following:

PS /home/user> powershell -Version 5.1                                          
-Version : The term '-Version' is not recognized as the name of a cmdlet, 
function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ -Version 5.1
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-Version:String) [], CommandNot 
   FoundException
    + FullyQualifiedErrorId : CommandNotFoundException

How to fix this?

2
  • use the ` $PSVersionTable.PSVersion` command. Commented Apr 24, 2020 at 4:48
  • 1
    powershell isn't available on *nix. It was changed to PowerShell Core/pwsh in the cross-platform version. PowerShell Core is from version 6.0 onward, the previous versions are Windows-only so you can't specify 5.1 or lower Commented Sep 19, 2024 at 15:36

2 Answers 2

1

PowerShell was written for Windows, which assumes an underlying filesystem where case does not matter. When you enter a PowerShell command, the program reads whatever you type, and then matches it against its idea of what the case ought to be and redisplays that.

When this question was asked in August 2016, the help-message for PowerShell showed the option as -Version:

-Version
    Starts the specified version of Windows PowerShell. 
    Enter a version number with the parameter, such as "-version 2.0".

The error message is saying that it expected to find a match using the filesystem's notion of the fully-spelled name. You will probably have better success if you use the mixed-case names as indicated in the help-message.

That message was changed about a year later, in issue #4958 which stated in effect that the feature did not actually work. OP's question dealt with asking the reason for the error message, which is explained by the message-file (a partly-implemented feature, which has since been removed).

3
  • This does not work either. Commented Aug 31, 2016 at 9:22
  • 4
    Raise a bug report. It is an alpha release, after all. Commented Aug 31, 2016 at 11:06
  • That link currently shows -Version | -v: Displays the version of PowerShell. Additional parameters are ignored. so you can't use -version 2.0 Commented Sep 19, 2024 at 15:34
0

On Ubuntu seems to work fine:

thufir@dur:~$ 
thufir@dur:~$ pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/thufir> 
PS /home/thufir> $PSVersionTable.PSVersion                                                                              

Major  Minor  Patch  PreReleas BuildLabel 
                     eLabel               
-----  -----  -----  --------- ---------- 
6      0      1                           


PS /home/thufir> 
PS /home/thufir> get-host                                                                                               


Name             : ConsoleHost
Version          : 6.0.1
InstanceId       : 914b71f4-0e73-461c-b1c3-f04753e5ed34
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-CA
CurrentUICulture : en-CA
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace



PS /home/thufir> 
PS /home/thufir> $PSVersionTable                                                                                        

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      6.0.1                                                                                   
PSEdition                      Core                                                                                    
GitCommitId                    v6.0.1                                                                                  
OS                             Linux 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:13:46 UTC 2018                     
Platform                       Unix                                                                                    
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 
WSManStackVersion              3.0                                                                                     


PS /home/thufir> 
PS /home/thufir> exit                                                                                                   
thufir@dur:~$ 
thufir@dur:~$ pwsh hello_world.ps1 
hello powershell world
thufir@dur:~$ 
thufir@dur:~$ ./hello_world.ps1 
hello powershell world
thufir@dur:~$ 
thufir@dur:~$ cat hello_world.ps1 
#!/usr/bin/pwsh -Command


"hello powershell world"
thufir@dur:~$ 

you'll have to clarify the problem. You can't find the version for pwsh?

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.