Everything about determining your PowerShell version - Svendsen Tech
Jump to page sections
There are a few ways to find which version of PowerShell you're running. $PSVersionTable.PSVersion exists in v2 and up, and you can use $Host.Version in v1.x - so long as you make sure you use powershell.exe or powershell_ise.exe. Other hosting applications, such as PowerGUI, set their own version numbers in $Host.Version and (Get-Host).Version (correctly so).

If you've looked at the directory structure and found "v1.0" - don't be fooled - it can still be Powershell v2 or later. From what I've read, Microsoft originally had planned to use different directories, but later changed their mind - for backwards compatibility reasons if I am to venture a guess. So now they, and we, are stuck with this "v1.0" folder.

Note made 2022-01-25: This has been remedied in PowerShell 7 / PowerShell Core. The path there has versions, under $Env:ProgramFiles\PowerShell\<Version> (and not just one static version! Poor Jeffrey Snover for that one... 😂).

There's a list of all the different PowerShell executable file system locations here in this article.

Also see this article about a script for finding which version(s) of the .NET Framework are installed on your local or even remote workstations or servers. I heavily recommend the "DotNetVersionLister" module there. You can install DotNetVersionLister from the PowerShell gallery, a Microsoft project and online repository for scripts. It's also on GitHub here.


Displaying PowerShell version with PowerShell v2 and up

With PowerShell v2 and up, you can enter $PSVersionTable at the prompt, and look at the "PSVersion" property:
PS C:\> $PSVersionTable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.5446
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
PSRemotingProtocolVersion      2.1

To index into a property of the object and display only the PSVersion property, and then further into the "Major" property under there, you can just use the dot operator.
PS C:\temp> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1      

PS C:\temp> $PSVersionTable.PSVersion.Major

PS C:\temp>

You can also call the .ToString() method on the PSVersion property of the $PSVersionTable variable for a nice display:

PS C:\> $PSVersionTable.PSVersion.ToString() 5.1.15063.608

Displaying major and minor version separated by a period

PS C:\> [String] $PSVersionTable.PSVersion.Major + "." + $PSVersionTable.PSVersion.Minor

PS C:\> "$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)"

Displaying PowerShell version with PowerShell v1

With PowerShell version 1, you can inspect the variable $Host and the property Version to see which version of PowerShell is running. You need to make sure you use powershell.exe or powershell_ise.exe, though, not PowerGUI or another hosting application, because these (may) set their own version here.

PowerShell version 1 doesn't have the $PSVersionTable variable mentioned above. The $Host variable is in PowerShell v2 as well.

Currently this is the output from PowerShell v2 (I actually don't have any computer still running v1 around):
PS C:\> $Host.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

You can also create a simple function that checks for the existence of $PSVersionTable, introduced in PowerShell version 2, and if it doesn't exist, it returns "1.0".

Possibly throw on -ErrorAction SilentlyContinue for Test-Path.
PS C:\temp> function Get-PSVersion {
    if (Test-Path -Path Variable:\PSVersionTable -EA Silent) {
    } else {

PS C:\temp> Get-PSVersion

Major Minor Build Revision ----- ----- ----- -------- 4 0 -1 -1

Using Get-Host

You can also use the cmdlet Get-Host, and look at the "Version" property:
PS C:\> Get-Host

Name             : ConsoleHost
Version          : 2.0
InstanceId       : a3a9b37c-61a4-478d-bcf6-b3e0f1b93f26
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : nb-NO
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
PS C:\temp> (Get-Host).Version

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1      

PS C:\temp> (Get-Host).Version.Major

PS C:\temp> 

= More obscure =

Yet another way, that returns the same as "$Host.Version" in my PowerShell v2, is looking at the default runspace:
PS C:\> [System.Management.Automation.Runspaces.Runspace]::DefaultRunspace.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
    Powershell     Windows     .NET     All Categories

Google custom search of this website only

Minimum cookies is the standard setting. This website uses Google Analytics and Google Ads, and these products may set cookies. By continuing to use this website, you accept this.

If you want to reward my efforts