Determine installed PowerShell version

Learn determine installed powershell version with practical examples, diagrams, and best practices. Covers powershell, version development techniques with visual explanations.

How to Determine Your Installed PowerShell Version

A stylized PowerShell icon with version numbers floating around it, representing different ways to check the version.

Learn various methods to accurately identify the PowerShell version installed on your system, crucial for compatibility and troubleshooting.

Knowing your PowerShell version is fundamental for scripting, module compatibility, and troubleshooting. Different versions introduce new cmdlets, features, and syntax changes, making it essential to verify which version you are running. This article will guide you through several reliable methods to determine your installed PowerShell version, covering both Windows PowerShell and PowerShell Core (now simply 'PowerShell').

Understanding PowerShell Versions

Before diving into the commands, it's important to distinguish between Windows PowerShell and PowerShell Core. Windows PowerShell is built on the .NET Framework and is pre-installed on Windows operating systems. PowerShell Core (now just PowerShell) is cross-platform, built on .NET Core, and can be installed on Windows, macOS, and Linux. The versioning schemes are distinct, with Windows PowerShell typically having versions like 5.1, and PowerShell Core starting from 6.0 and continuing upwards (e.g., 7.0, 7.1, 7.2).

flowchart TD
    A[Start PowerShell] --> B{Check $PSVersionTable}
    B --> C[Identify PSVersion property]
    C --> D{Is it 5.1 or lower?}
    D -->|Yes| E[Windows PowerShell]
    D -->|No| F[PowerShell Core/7+]
    F --> G{Check $Host.Version}
    G --> H[Identify Host Version]
    H --> I[End]

Flowchart for determining PowerShell version type.

Method 1: Using the $PSVersionTable Automatic Variable

The $PSVersionTable automatic variable is the most comprehensive and recommended way to get detailed information about your PowerShell installation. It's a hash table that contains several properties, including the PSVersion which directly tells you the engine version.

$PSVersionTable

Displaying the full $PSVersionTable.

To get just the version number, you can access the PSVersion property directly:

$PSVersionTable.PSVersion

Retrieving only the PowerShell engine version.

Method 2: Using the $Host Automatic Variable

The $Host automatic variable provides information about the current host program that is running PowerShell. Its Version property can also be used to determine the PowerShell version, though it might sometimes reflect the host application's version rather than the engine's in older PowerShell versions.

$Host.Version

Displaying the host application's version.

Method 3: Using Get-Host Cmdlet

The Get-Host cmdlet provides similar information to the $Host automatic variable. It returns an object representing the current host program, which includes a Version property.

Get-Host | Select-Object Version

Using Get-Host to retrieve the version.

Method 4: Checking the PowerShell Executable Path

For PowerShell Core (versions 6.0 and higher), the executable is typically named pwsh.exe, while for Windows PowerShell, it's powershell.exe. You can often infer the major version by checking the executable's path or by simply running the executable with the -Version switch (though this is less common for direct version output).

(Get-Command powershell.exe).Source
(Get-Command pwsh.exe).Source

Locating the executable paths for PowerShell.