Microsoft PowerShell is a shell that’s built using Microsoft .NET technology. It’s designed to aid developers in building efficient scripts and tools to automate and speed up various processes. It was originally inspired by other scripting languages like VBScript and batch files.

PowerShell combines the command-line shell that can run commands similar to a classic shell (bash, zsh, etc.) and a scripting language. PowerShell is object-oriented, similar to object-oriented programming.

This guide will demonstrate how to check the installed version of PowerShell using various PowerShell commands and variables.

Installing PowerShell

PowerShell was a Windows-exclusive feature and was available on all the major Windows releases when it first came out. Starting from PowerShell 6.0, it’s become free and open-source software, available for all the major platforms (Windows and Linux). It’s now available for all the major Linux distros.

For distro-specific installation instructions, check out the official Microsoft documentation on PowerShell installation on Linux. Thankfully, PowerShell is also available as a snap package on the Snapcraft store. The snap packages can be installed on a wide range of Linux distros without any modification.

Check out PowerShell on Snapcraft store.

The following command will install PowerShell snap.

$ sudo snap install powershell –classic

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-232.png" data-lazy- height="173" src="data:image/svg xml,” width=”1218″>

Let’s perform a quick verification if PowerShell was installed successfully.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-233.png" data-lazy- height="267" src="data:image/svg xml,” width=”1213″>

Getting PowerShell version

In any programming/scripting language, there are multiple ways to reach a certain destination. It applies to PowerShell as well. We can check the PowerShell version using a handful of methods. It revolves around multiple PowerShell built-in features.

Keeping track of the PowerShell version is important in various scenarios. The system admin may want to stay up-to-date to avoid running old PowerShell. For developers, script compatibility is necessary to maintain. For general/advanced users, having the latest PowerShell offers additional features and enhanced security (patches, bug fixes, and other improvements).

Check PowerShell version using $PSVersionTable

When running the command, it will print a PowerShell hash table containing various info about PowerShell.

Run the command in PowerShell:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-234.png" data-lazy- height="459" src="data:image/svg xml,” width=”1215″>

To get the PowerShell version only, use the following command.

$ $PSVersionTable.PSVersion

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-235.png" data-lazy- height="237" src="data:image/svg xml,” width=”1213″>

PowerShell allows fine-tuning the output to print only specific info. In the next demonstration, we’ll get the in-depth version of the running PowerShell.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-236.png" data-lazy- height="853" src="data:image/svg xml,” width=”1213″>

If you’re running PowerShell 7 or later, it also comes with backward compatibility with older releases. Check the supported backward-compatible PowerShell releases.

$ $PSVersionTable.PSCompatibleVersions

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-237.png" data-lazy- height="491" src="data:image/svg xml,” width=”1215″>

Check PowerShell version using Get-Variable

As the name suggests, the command Get-Variable allows you to read the value of a variable in PowerShell. Using this command, we can extract the value of the variable $PSVersionTable. This method is the same as before, except we’ll be using Get-Variable to do the job. Have a quick look at checking environment variables in PowerShell.

To print the version of PowerShell, run the following command.

$ (Get-Variable PSVersionTable -ValueOnly).PSVersion

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-238.png" data-lazy- height="254" src="data:image/svg xml,” width=”1214″>

Check PowerShell version using Get-Host

In PowerShell, a host is a program that’s hosting the PowerShell engine. The Get-Host command offers a wealth of info about the host (including various PowerShell info).

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-239.png" data-lazy- height="470" src="data:image/svg xml,” width=”1216″>

To get the PowerShell version specifically, run the following command instead.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-240.png" data-lazy- height="253" src="data:image/svg xml,” width=”1214″>

Alternatively, we can pass the output of Get-Host to Select-Object to show the “Version” field only.

$ Get-Host | Select-Object version

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-241.png" data-lazy- height="254" src="data:image/svg xml,” width=”1214″>

Check PowerShell version using $Host automatic variable

The $Host variable in PowerShell contains various information about the host. It also includes the PowerShell version.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-242.png" data-lazy- height="448" src="data:image/svg xml,” width=”1213″>

To get specifically the PowerShell version, use the following command instead.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/word-image-243.png" data-lazy- height="255" src="data:image/svg xml,” width=”1213″>

Final thoughts

This guide demonstrates all the possible ways of checking the version of PowerShell installed. It also showcases how to extract the info more conveniently with the help of some basic PowerShell scripting. For reliable version info, it’s always recommended to use $PSVersionTable.PSVersion as the reference.

PowerShell scripting can achieve a lot more. For beginners, check out this step-by-step guide on writing a PowerShell script.

Happy computing!

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/profile-photo-1-150×150.jpg616b5776b7e3c.jpg" height="112" src="data:image/svg xml,” width=”112″>

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.