There are multiple approaches to check what version of PowerShell is installed on the machine. Two of the best approaches are listed below.
- $PSVersionTable
- Get-Host
How to Determine installed PowerShell Version?
If the PowerShell version 2.0, 3.0, 4.0 or 5.0 and above is installed in the machine then Get-Host will run properly and below is the result that it provides when you run Get-Host
.
PS C:\> Get-Host
Name : ConsoleHost
Version : 5.0.10586.122
InstanceId : 48251136-d3c4-4e38-81c2-2394611f26f1
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PS C:\>
The instance ID from machine to machine will be different and Get-Host
will not return the proper result if you are running the command via a remote PowerShell session.
$PSVersionTable
is the best command to run and it will produce the following results when you run on machines with PowerShell 2.0, 3.0, 4.0 and 5.x installed.
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.0.10586.122
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.122
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Alternatively, if you need just need only the Major and Minor version details then you could use the command $PSVersionTable.PSVersion
. This will return you the following output in the console.
PS C:\> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 0 10586 122