How to Get PowerShell Version

Migel Hewage Nimesha Feb 02, 2024
  1. Use the $PSVersionTable.PSVersion Property to Get PowerShell Version
  2. Use the (Get-Host).Version Property to Get PowerShell Version
  3. Use the $host.Version Property to Get PowerShell Version
  4. Use Registry to Get PowerShell Version
How to Get PowerShell Version

PowerShell is a type of command prompt that is more complex. It comes with a large number of prepared cmdlets and the ability to leverage the .NET framework/C# in various scenarios. PowerShell ISE is a graphical user interface for debugging and editing scripts on Windows. In PowerShell, the same thing can be done a different number of ways. So mainly, there are four ways we can get the version of PowerShell, and they are given below.

Use the $PSVersionTable.PSVersion Property to Get PowerShell Version

So the first method we are looking into is the PSVersion attribute in the automatic variable $PSVersionTable. Here, it represents the PowerShell engine.

PS52> $PSVersionTable.PSVersion

Output:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1320

$PSVersionTable is a read-only hash-table that gives information on the PoweShell engine version as well as PSEdition. This parameter can be either Desktop or Core, and it will provide you with additional information about the PowerShell edition you’re using.

The automated variable $PSVersionTable is as accurate locally as it would be remotely. I in the example below that enclosing $PSVersionTable. PSVersion inside a script block and running it on a remote machine returns the same version.

PS> Invoke-Command -ComputerName 11.0.0.3 -ScriptBlock {$PSVersionTable.PSVersion} -Credential $cred

Output:

Use the $PSVersionTable.PSVersion property to Get PowerShell Version

Use the (Get-Host).Version Property to Get PowerShell Version

The idea of hosts is used in PowerShell. It isn’t the PowerShell engine that is causing the issue. PowerShell hosts are PowerShell code editor/console with a built-in terminal. The host could have a totally self-contained edition of PowerShell.

When (Get-Host).Version is used, it outputs a version number similar to the PowerShell version.

PS52> (Get-Host).Version

Output:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1320

However, the version of Get-Host in the built-in terminal isn’t always the same. Even though the host normally represents the very same edition of the PowerShell engine, this is not always the case. When Get-Host is called on a local computer, it always returns the same version but never on remote systems.

Therefore using Get-Host for everything is a terrible idea.

Use the $host.Version Property to Get PowerShell Version

.$host.Version is another method to get the PowerShell engine version. Get-Host delivers the same result as the $host variable, a fully automated variable.

PS52> $host.Version

Output:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  1320

This is quite similar to the Get-host method.

Use Registry to Get PowerShell Version

You may also check the registry only if you aren’t keen on launching PowerShell. The edition of PowerShell is stored in the registry key path as follows HKLM:\SOFTWARE\Microsoft\PowerShell\3\ and also as a value. Get-ItemProperty may be used to reference the PowerShellVersion value in this registry entry.

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

Output:

5.1.19041.1
Migel Hewage Nimesha avatar Migel Hewage Nimesha avatar

Nimesha is a Full-stack Software Engineer for more than five years, he loves technology, as technology has the power to solve our many problems within just a minute. He have been contributing to various projects over the last 5+ years and working with almost all the so-called 03 tiers(DB, M-Tier, and Client). Recently, he has started working with DevOps technologies such as Azure administration, Kubernetes, Terraform automation, and Bash scripting as well.