How to get the “Windows PowerShell” version? `pwsh –version` seems to be giving the “PowerShell 7” version

In both “PowerShell 7” and “Windows PowerShell”, when I do pwsh --version, I get PowerShell 7.4.5.

However, in “Windows PowerShell”, when I do Set-PSReadLineOption -PredictionSource HistoryAndPlugin [1], I get the following error

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Set-PSReadLineOption : The prediction plugin source is not supported in this version of PowerShell. The 7.2 or a
higher version of PowerShell is required to use this source.
At line:1 char:1
+ Set-PSReadLineOption -PredictionSource HistoryAndPlugin
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-PSReadLineOption], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.SetPSReadLineOption
</code>
<code>Set-PSReadLineOption : The prediction plugin source is not supported in this version of PowerShell. The 7.2 or a higher version of PowerShell is required to use this source. At line:1 char:1 + Set-PSReadLineOption -PredictionSource HistoryAndPlugin + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Set-PSReadLineOption], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.SetPSReadLineOption </code>
Set-PSReadLineOption : The prediction plugin source is not supported in this version of PowerShell. The 7.2 or a
higher version of PowerShell is required to use this source.
At line:1 char:1
+ Set-PSReadLineOption -PredictionSource HistoryAndPlugin
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-PSReadLineOption], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.SetPSReadLineOption

indicating that “Windows PowerShell” is not actually in version 7.4.5. So how do I get the actual version of “Windows PowerShell”?

Having two PowerShells is already confusing enough. It would appear “PowerShell 7” is leaking state onto “Windows PowerShell” to have it say it’s in version 7.4.5, when it’s not.

Any recommendations to avoid confusion going forward? Should I just use “PowerShell 7” exclusively?


[1] command comes from
PowerShell docs on “Using predictors in PSReadLine”

pwsh --version

Displays the version of this PowerShell exectuable. Additional parameters are ignored.

returns the version of the pwsh.exe command not the version of the current CLI (command line interface). I guess this parameter is originated from the cross-platform Linux operating system, see also: How to check installed program version?

This means that pwsh --version is indeed supposed to return its own executable version number (e.g. PowerShell 7.4.5) even if you give this command from another shell, as the good old cmd prompt. Just as the other way around –using the cmd --version command under PowerShell (or any other CLI)– would return the CMD command version:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>cmd --version
Microsoft Windows [Version 10.0.19045.4780]
(c) Microsoft Corporation. All rights reserved
</code>
<code>cmd --version Microsoft Windows [Version 10.0.19045.4780] (c) Microsoft Corporation. All rights reserved </code>
cmd --version
Microsoft Windows [Version 10.0.19045.4780]
(c) Microsoft Corporation. All rights reserved

As you found out yourself, the correct way to check the current PowerShell version is using the $PSVersionTable command (see also: Determine installed PowerShell version):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Windows PowerShell
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.4780
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.4780
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
</code>
<code># Windows PowerShell $PSVersionTable Name Value ---- ----- PSVersion 5.1.19041.4780 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.4780 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 </code>
# Windows PowerShell
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.4780
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.4780
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

This represents the current PowerShell version that corresponds to the same version of the executable (pwsh.exe) that has been initially launched (possibly through a shortcut).
This will also show in the following command that opens a temporary (PowerShell 7.4.5) shell and returns the results the current command line independent of the current CLI (version):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>pwsh -Command '$PSVersionTable'
Name Value
---- -----
PSVersion 7.4.5
PSEdition Core
GitCommitId 7.4.5
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
</code>
<code>pwsh -Command '$PSVersionTable' Name Value ---- ----- PSVersion 7.4.5 PSEdition Core GitCommitId 7.4.5 OS Microsoft Windows 10.0.19045 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 </code>
pwsh -Command '$PSVersionTable'

Name                           Value
----                           -----
PSVersion                      7.4.5
PSEdition                      Core
GitCommitId                    7.4.5
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

1

pwsh --version gives the “PowerShell 7” version even though I called it from “Windows PowerShell”, but $PSVersionTable gives the correct version:

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật