Powershell

How to Check the PowerShell Version Installed

By May 26, 2021January 15th, 2022No Comments

In this post we will learn what PowerShell versions exist, what is the difference between Windows PowerShell and PowerShell Core, and how to check the PowerShell version installed on a local or remote computer.

History and Versions of Windows PowerShell and PowerShell Core

PowerShell is installed by default in all Windows versions starting from Windows 7 SP1 and Windows Server 2008 R2 SP1. The following table shows the list of all PowerShell versions:

PS VersionNote
PowerShell 1.0Can be installed manually on Windows Server 2003 SP1 and Windows XP
PowerShell 2.0Windows Server 2008 R2 and Windows 7
PowerShell 3.0Windows 8 and Windows Server 2012
PowerShell 4.0Windows 8.1 and Windows Server 2012 R2
PowerShell 5.0Preinstalled on Windows 10 RTM and automatically updated to 5.1 via Windows Update
PowerShell 5.1It is built into Windows 10 (starting with Build 1709) and Windows Server 2016
PowerShell Core 6.0 and 6.1It is the next cross-platform PowerShell version (based on .NET Core) that may be installed on all supported Windows versions and on MacOS, CentOS, RHEL, Debian, Ubuntu, openSUSE
PowerShell Core 7.0It is the latest PowerShell version released in March, 2020 (.NET Core 3.1 is used in it instead of .NET Core 2.x)

You can manually install a newer PowerShell version in previous Windows versions. To do it, download and install the appropriate version of the Windows Management Framework (PowerShell is a part of it).

It is worth noting that in the last 2 years Microsoft suspended the development of classic Windows PowerShell (only bug fixes and security updates are released) and focused on open-source cross-platform PowerShell Core.

What’s the difference between Windows PowerShell and PowerShell Core?

  1. Windows PowerShell is based on .NET Framework (for example, PowerShell 5 requires .NET Framework v4.5, make sure that it is installed). PowerShell Core is based on .Net Core;
  2. Windows PowerShell works only in Windows operating systems, while PowerShell Core is cross-platform and can work in Linux as well;
  3. PowerShell Core is not fully compliant with Windows PowerShell, however, Microsoft is working on the improving of backward compatibility with earlier PS cmdlets and scripts. (it is recommended to test your old PS1 scripts before moving to PowerShell Core). PowerShell Core 7 provides the highest compatibility with Windows PowerShell;
  4. You cannot use the PowerShell ISE Editor to edit PowerShell Core scripts (but Visual Studio Code can be used);
  5. Since Windows PowerShell is no longer developed, it is recommended that you start migrating to PowerShell Core.

How to Get PowerShell Version from the Console?

The easiest way to find out which PowerShell version is installed on your computer is to use the command:

host

Check the Version property value.The following screenshot was made in Windows 10 having PowerShell 5.1 installed by default, like in Windows Server 2016.

Find PowerShell Version in Windows

or

$PSVersionTable

You can get the PowerShell version value only:

$PSVersionTable.PSVersion.major

(in this example we got PSVersion 2.0 in clean Windows Server 2008 R2)

$PSVersionTable

The $PSVersionTable command correctly works in PowerShell Core in different operating systems.

You can also find out the installed PowerShell version through the registry. To do it, get the value of the PowerShellVersion parameter in the registry key HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine using Get-ItemProperty cmdlet:

(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion

check powershell version in registry

The method described above works on Windows Server 2012/Windows 8 or newer.

In Windows Server 2008 R2/Windows 7, you can get the value of the registry parameter in another reg key:

(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion

get 'PowerShellVersion' on windows server 2008 r2 / winn 7

To get the installed PowerShell Core version, use the following command:

(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions* -Name 'SemanticVersion').SemanticVersion

Check Version of PowerShell on Remote Computers

To check the PowerShell version on a remote host, use the value of the $PSVersionTable environment variable or get the information from the registry directly. Other methods may return incorrect data.

You can get the PowerShell version installed on a remote computer via PowerShell Remoting using the Invoke-Command cmdlet:

Invoke-Command -ComputerName mun-dc01 -ScriptBlock {$PSVersionTable.PSVersion} -Credential $cred
Get remote computer Powershell version using invoke-command

Major Minor Build Revision PSComputerName
----- ----- ----- -------- --------------
5 1 14393 3383 mun-dc01

You can get the installed PowerShell versions on multiple computers using the following script (the list of remote computers must be specified as a plain text file):

Invoke-Command -ComputerName (Get-Content C:\PS\host_list.txt) -
ScriptBlock{$PSVersionTable.PSVersion} | Select PSComputerName, @{N="PS Version";E={$_.Major}}

Or you can get a list of domain computers via Get-ADComputer and remotely check the PowerShell versions on them:

$adcomputer=(Get-ADComputer -Filter 'operatingsystem -like "*Windows server*" -and enabled -eq "true"' -SearchBase ‘OU=servers,OU=America,dc=contoso,dc=com’ ).Name
Invoke-Command-ComputerName $adcomputer -Scriptblock{$PSVersionTable.psversion} -ErrorAction SilentlyContinue
If your PowerShell script uses features of a specific PS version, you can force your script to switch to a different PowerShell version. For example, to run a console in PowerShell v3 mode, run this command (.Net Framework 3.5 must be installed):

PowerShell.exe -version 3

It may be important to know your PowerShell version if you run scripts or commands that use the cmdlets or features of a specific PS version. If you want to detect the installed PowerShell version in the script and use cmdlets based on it, you can run the following PS script:

$ps_version = $PSVersionTable.PSVersion.major
if ( $ps_version -eq "2” )
{
write "You are using Powershell 2.0"
}
elseif ( $ps_version -eq "5" )
{
write " You are using Powershell 5"
}

Leave a Reply