How to Check PowerShell Version?

Checking the version of PowerShell is a straightforward process that can be performed within the tool itself. Microsoft has provided multiple methods to determine the version, each varying slightly based on preference or system constraints. Being aware of the installed version helps administrators leverage the appropriate capabilities of PowerShell and guarantees that any commands executed are compatible with the version in use.

The command line provides the easiest approach to identify the version of PowerShell. Simple execution of a few built-in commands or accessing specific system variables can reveal detailed information about the version installed. This knowledge becomes a prerequisite when users plan to update scripts, use newer commands, or troubleshoot compatibility issues with PowerShell modules.

Understanding PowerShell

PowerShell is a task-based command-line shell and scripting language built on .NET. It helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

History of PowerShell Versions

PowerShell has evolved significantly since its release. Here is a brief overview of its version history:

  • PowerShell 1.0: Introduced in 2006 as a new task-based scripting technology with a batch processing feature.
  • PowerShell 2.0: Added advanced functions, remote management, and background jobs.
  • PowerShell 3.0: Brought workflow functionality, improved the cmdlet discovery, and enhanced the language.
  • PowerShell 4.0: Included Desired State Configuration and more default cmdlets.
  • PowerShell 5.0: Introduced powerful new features like software discovery, installation, and inventory (SDII), PowerShellGet, and enhanced Desired State Configuration (DSC).
  • PowerShell 7.0: It enhanced display of error messages, which improves the readability of interactive and script errors with a new default view

Each version incorporated improvements, new features, and bug fixes to enhance the overall utility and compatibility of PowerShell.

Features of Different PowerShell Versions

Different versions of PowerShell offer varying capabilities:

VersionKey Features
PowerShell 1.0130 cmdlets, script debugging, consistent syntax
PowerShell 2.0Remote management, modules, advanced functions
PowerShell 3.0Workflow, enhanced session connectivity, Disconnected sessions
PowerShell 4.0Desired State Configuration, better syntax, Enhanced sessions for VMs
PowerShell 5.0PowerShellGet, .NET Framework 4.6 integration, classes and enumerated types
PowerShell 7.0One of the new features introduced in PowerShell 7.0 is the enhanced display of error messages, which improves the readability of interactive and script errors with a new default view

PowerShell Editions

There are two main editions of PowerShell that are currently maintained:

  • Windows PowerShell: Built on the .NET Framework, Windows-specific, containing cmdlets for managing Windows components.
  • PowerShell Core: The cross-platform (Windows, Linux, and macOS) edition built on .NET Core known for its enhanced performance and SSH-based remote management.

Starting with PowerShell 5.0, there’s been a marked emphasis on open-source and cross-platform capabilities, culminating in PowerShell 7, which continues to unify and extend functionalities across different environments. Each edition of PowerShell supports a semantic versioning scheme that signals to the user compatibility and the scope of changes introduced.

How to Find PowerShell Version

When an individual needs to determine which version of PowerShell is installed on their system, they can use either the $PSVersionTable variable or specific cmdlets within PowerShell.

Using $PSVersionTable

The $PSVersionTable is a predefined variable in PowerShell that contains details about the version of PowerShell in use. To view the version number, one simply needs to open PowerShell, type the following command, and press Enter:

$PSVersionTable

The output will display various properties, including PSVersion, which indicates the version of PowerShell installed. The display might look something like this:

PropertyValue
PSVersion5.1.19041.546
PSEditionDesktop

The PSVersion row shows the PowerShell version number.

Utilizing Command-Line Cmdlets

Apart from using the $PSVersionTable variable, one can also invoke specific cmdlets to check the PowerShell version. The (Get-Host).Version and $host.Version properties are both accessible via the following commands:

Using Get-Host cmdlet:

(Get-Host).Version

Using $host variable:

$host.Version

These commands return the version number of the PowerShell engine. The command-line method is particularly useful for scripting scenarios or for incorporating version checks into larger automated tasks.

Additionally, for users who need to check the version of Windows PowerShell specifically, they can examine the registry keys using the built-in regedit tool or command-line reg query. This can be particularly relevant on systems where multiple versions of PowerShell, including legacy Windows PowerShell, might be installed. In such cases, the registry query would look like this:

reg query "HKLM:\Software\Microsoft\PowerShell\3\PowerShellEngine" /v PowerShellVersion

The output will provide the value associated with the PowerShellVersion key from the registry, which represents the installed version of Windows PowerShell.

How to Check PowerShell Version in Windows

To determine the version of PowerShell on a Windows machine, one can employ several methods. Each method provides the same basic information but may be presented slightly differently.

Using the $PSVersionTable Variable:

  1. Open a PowerShell window.
  2. Type the following command and press Enter:
$PSVersionTable

The output will display various information, including the PSVersion which indicates the PowerShell version installed.

Using the $host Object:

  1. Open a PowerShell window.
  2. Execute the following command:
$host

Again, look for the Version information to identify the PowerShell version.

Alternatively, use this command for a more specific output:

$host.Version

Checking the Registry (For Windows PowerShell only):

For versions before PowerShell Core (version 6+), the Windows Registry contains details about the installed PowerShell version.

Using Get-Host Cmdlet:

The Get-Host cmdlet can also be invoked to find the version of PowerShell:

  1. Open PowerShell.
  2. Input the following:
Get-Host | Select-Object Version

The command will return the version number clearly.

These methods provide a straightforward approach to determine the PowerShell version installed on a Windows system, which is essential for compatibility and scripting purposes.

How to Find PowerShell Version in Windows Server

To identify the version of PowerShell installed on a Windows Server, an administrator can follow these straightforward steps. It’s important to ascertain the correct version, as different server tasks and scripts might require compatibility with specific versions of PowerShell.

Method 1: Use $PSVersionTable

One can easily check the version using the built-in variable $PSVersionTable.

$PSVersionTable.PSVersion

This command will display an object containing the major, minor, build, and revision numbers of the installed PowerShell version.

Method 2: Use Get-Host

Alternatively, administrators may use the Get-Host command:

Get-Host | Select-Object Version

This outputs the version information directly associated with the PowerShell host program.

Accessing via the Registry

For users who prefer not to use the command line, checking the registry can also provide the necessary information:

  • PowerShell 1.0 or 2.0: One should look at the registry key located at: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine
  • PowerShell 3.0 and above: Check the registry key at: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine

The registry contains a value titled ‘PowerShellVersion’ which will display the version number.

Always ensure to check the version compatibility with certain applications and scripts before attempting to run them on the Windows Server. Knowing the PowerShell version can help preempt issues related to scripting or automation tasks.

How to Check PowerShell Version in Linux

To identify the PowerShell version on a Linux system, one can leverage the command-line interface efficiently. The process is straightforward.

Step-by-Step Guide:

  1. Open the Terminal
    The user begins by opening the Terminal application, which is the gateway to using command-line utilities in Linux.
  2. Enter the PowerShell Environment
    If PowerShell is already installed, one can access it by typing pwsh and pressing Enter. This launches PowerShell Core, Microsoft’s cross-platform edition of PowerShell.
  3. Check the Version
    Once in the PowerShell environment, the user can retrieve the version information by running the following command: $PSVersionTable.PSVersion This command outputs a table containing various details, including the desired version number of PowerShell.

Additional Information:

  • Alternative Command:
    Users can also employ an alternative command, which directly queries the version: pwsh -version
  • PowerShell Core Identification:
    It’s important to note that on Linux, the version pertains to PowerShell Core, which is distinct from the PowerShell available in Windows environments.

This method ensures users can confidently ascertain the currently installed version of PowerShell on their Linux system in a clear, concise manner.

How to Check PowerShell Version in Visual Studio Code

When using Visual Studio Code (VS Code), one may need to determine the version of PowerShell they are working with, especially when configuring the PowerShell extension or scripting across different environments. To check the PowerShell version within VS Code, follow these steps:

  1. Open Command Palette: Use the keyboard shortcut Ctrl+Shift+P on Windows or Linux, or Cmd+Shift+P on macOS to open the Command Palette.
  2. Execute PowerShell Command: Type in PowerShell: Show Session Menu and select it. This will bring up the version information at the top of the integrated console.
  3. Review Version Information: The integrated console will display the version of PowerShell which is currently active in VS Code. It may look something like this: PowerShell 7.1.3 Copyright (c) Microsoft Corporation. https://aka.ms/powershell Type 'help' to get help.
  4. Alternative Method: The version can also be checked using an automatic variable $PSVersionTable by typing it into the integrated console and pressing Enter. This will output a table containing version details.

The following is an example output after running $PSVersionTable:

PropertyValue
PSVersion7.1.3
PSEditionCore
GitCommitId7.1.3
OSLinux 4.18.0-193.14.2.el8_2.x86_64
PlatformUnix

This table provides comprehensive data about the PowerShell version, including the edition and the operating system details.

Using these straightforward steps, developers can confidently and accurately check the PowerShell version within Visual Studio Code, facilitating effective PowerShell development and debugging sessions within the editor.

check powershell version in visual studio code

How to Check PowerShell Version in Command Prompt

To ascertain the version of PowerShell, one can utilize the Command Prompt in Windows. The process is straightforward and can be accomplished through a few simple steps.

Firstly, launch the Command Prompt by searching for cmd in the Windows search bar and selecting it from the results. Inside the Command Prompt window, one must initialize PowerShell by inputting the command powershell and pressing Enter. This action transitions the environment from Command Prompt to PowerShell.

Once PowerShell is activated, the user should type the command Get-Host | Select-Object Version and then press Enter. This will display the current version of PowerShell installed on the system. The version information is presented clearly, typically in a format resembling Version 5.1.19041.546.

For users requiring just the version number without additional details, a more concise command can be used:

$PSVersionTable.PSVersion

Inputting this command returns only the necessary version information, formatted neatly in a table:

MajorMinorBuildRevision
74

Each column represents a component of the PowerShell version, offering a granular view of the major, minor, build, and revision numbers. This method provides a quick way to verify the PowerShell version in Command Prompt, ensuring that users can confirm compatibility with scripts or determine if an update is necessary.

PowerShell in Different Environments

PowerShell operates across various environments, accommodating different operating systems and platforms. The intricacies of checking PowerShell version vary depending on the environment in which it is running.

Windows OS

On Windows operating systems, PowerShell is a built-in tool starting with Windows 7 and Server 2008 R2. The process to check the PowerShell version has been relatively consistent:

  • Windows 7 and Server 2008 R2 to Windows 8.1 and Server 2012 R2: Use Get-Host or $PSVersionTable in the PowerShell window to check the version.
  • Windows 10 and Server 2016: These versions come with Windows PowerShell 5.1 by default. To check, type $PSVersionTable.PSVersion in the PowerShell console.
  • Windows 11: While it also comes with PowerShell 5.1, Windows 11 includes improvements and updates, so confirming the version with $PSVersionTable is advised.

Cross-Platform Use

With the advent of PowerShell Core, users have a cross-platform version that runs on Windows, Linux, and macOS. PowerShell Core is built on .NET Core, enabling it to function across different operating systems:

  • Linux and macOS: The command pwsh --version can be used to check the PowerShell version.
  • Remote Hosts: When using PowerShell Core to connect to a remote host, one can check the version of PowerShell running on that host using the Invoke-Command cmdlet.

PowerShell and .NET Core

PowerShell Core leverages .NET Core for cross-platform compatibility:

  • .NET Core: PowerShell Core versions are based on .NET Core and have separate versioning from Windows PowerShell. To check the version, use $PSVersionTable which will include the .NET Core version it’s running on.
  • It’s important to note that while Windows PowerShell is built on the .NET Framework, PowerShell Core and higher are built on .NET Core, which allows for the cross-platform functionality.

Conclusion

In this PowerShell tutorial, I have explained how to check the PowerShell version.

  • How to check PowerShell version in windows
  • How to check PowerShell version in linux
  • How to check PowerShell version in windows server
  • How to check PowerShell version in command prompt
  • How to check PowerShell version in visual studio code

You may also like: