In this article, you will learn how to do a PowerShell version check. Understanding which PowerShell you have installed is necessary to make sure it’s compatible with scripts, modules and features. PowerShell has evolved significantly over the years, transitioning from a Windows-only tool to an open-source, cross-platform framework known as PowerShell Core.
Introduction to PowerShell versioning
PowerShell, developed by Microsoft, was first introduced in 2006 as a task automation framework primarily for Windows systems. Over the years, it has evolved significantly, leading to various versions of PowerShell, each with its own set of features, improvements, and compatibility considerations.
The original PowerShell, now often referred to as Windows PowerShell, was closely tied to the Windows operating system and included in most Windows installations. However, as the need for cross-platform compatibility grew, Microsoft introduced and expanded upon their PowerShell versions until the latest, PowerShell Core, an open-source, cross-platform tool.
Why it’s important to know your PowerShell version
Knowing your PowerShell version is not just about staying current; it’s about making certain that your scripts and modules function as expected. Different PowerShell versions come with varying sets of cmdlets, features, and compatibility with external modules. Here are some reasons you should be aware of your PowerShell versions:
- Compatibility: Different PowerShell versions support different cmdlets, features, and external modules. A script written for PowerShell 7.x may not run on Windows PowerShell 5.1 due to differences in available cmdlets or syntax changes. Conversely, older scripts may fail on newer versions if they rely on deprecated features.
- Performance and features: Running older versions of PowerShell may mean missing out on significant performance improvements, security updates, and new functionalities introduced in later versions. These updates often include bug fixes and enhancements that make automation tasks more efficient and secure.
- Security: Microsoft regularly releases updates to address vulnerabilities and improve overall platform security. Using an outdated version of PowerShell can expose your systems to security risks, particularly if those versions are no longer supported with patches or updates.
- Troubleshooting: Understanding your PowerShell version is essential when troubleshooting issues. Knowing which version you are using can help you quickly identify if the problem is related to version compatibility, missing features, or deprecated functionality, allowing you to take appropriate action.
How to perform a PowerShell version check
Knowing your PowerShell version is straightforward and there are several methods you can use to determine it. Below, we’ll explore different techniques depending on your operating system and preferences.
Using the $PSVersionTable command
The most common and straightforward way to perform a PowerShell version check is by using the $PSVersionTable command. This command returns a table of information about your PowerShell environment, including the version number.
To perform a version check:
- Open PowerShell.
- Type “$PSVersionTable” and press “Enter.”
- Look for the PSVersion entry in the output. This value indicates the version of PowerShell installed on your system.
For example, if the PSVersion shows 5.1.19041.1023, you are running Windows PowerShell 5.1. The $PSVersionTable output also includes other valuable details, such as the CLR version (for Windows PowerShell) or the PSEdition, which distinguishes between Windows PowerShell and PowerShell Core.
This method is universally applicable across all platforms where PowerShell is installed, making it the go-to command for a quick PowerShell version check.
PowerShell version check via the registry
Another method to check your PowerShell version, particularly on Windows systems, is by examining the Windows Registry. This approach can be useful if you need to verify the version of PowerShell installed without opening the PowerShell console.
To check via the registry:
- Press Win + R on your keyboard, type “regedit” and press “Enter” to open the Registry Editor.
- Navigate to HKEY_LOCAL_MACHINESOFTWAREMicrosoftPowerShell3PowerShellEngine.
- Look for the PowerShellVersion entry. The value here represents the installed version of PowerShell.
This way is more technical and is typically used in scenarios where you need to programmatically perform a PowerShell version check or when working in environments where accessing the PowerShell console is restricted.
Identifying version differences on Windows vs. Mac/Linux
PowerShell version checks on macOS or Linux is similar to the process on Windows, but there are a few key differences to be aware of. On non-Windows systems, PowerShell is usually installed as PowerShell Core and the version can be checked using the same $PSVersionTable command in a terminal.
On these platforms, it’s important to note that PowerShell Core and PowerShell 7.x are the only versions available, as Windows PowerShell (versions 5.1 and earlier) is exclusive to Windows. When you run $PSVersionTable, you should see the PSEdition listed as Core, which distinguishes it from Windows PowerShell.
In addition to using the $PSVersionTable command, you can also check the version by typing “pwsh –version” in the terminal. This command directly outputs the version number of PowerShell Core installed on your system.
Common PowerShell versions and their features
PowerShell has undergone several major updates since its initial release, each bringing new features and enhancements. Below are the most common versions you might encounter and the features they offer.
Windows PowerShell 5.1:
- Compatibility: The last version of Windows PowerShell, version 5.1, is widely used in enterprise environments due to its integration with Windows. It supports a vast array of cmdlets and is compatible with many legacy scripts and modules.
- Security Enhancements: This version introduced improvements in script block logging and constrained language mode, enhancing security for administrators.
- Desired State Configuration (DSC): PowerShell 5.1 includes significant improvements to DSC, allowing for better configuration management across multiple machines.
PowerShell 6.0 (PowerShell Core):
- Cross-Platform: Marking a significant shift, PowerShell Core is the first version to support cross-platform usage, running on Windows, macOS and Linux.
- Performance: PowerShell Core 6.0 offers performance improvements over its predecessor, making it faster and more efficient.
- Open Source: PowerShell Core is open-source, allowing the community to contribute to its development and ensuring more frequent updates and improvements.
PowerShell 7.x:
- Unified Experience: PowerShell 7.x combines the best features of Windows PowerShell and PowerShell Core, offering a unified scripting environment that is both powerful and versatile.
- Pipeline Parallelization: Introduced in PowerShell 7.0, this feature allows for faster processing of data by running pipeline commands in parallel.
- Enhanced Error Handling: PowerShell 7.x includes new error handling features, such as -ErrorAction and -ErrorVariable, providing more control over how scripts handle exceptions.
How to Update PowerShell to the Latest Version
Keeping your PowerShell installation up-to-date is considered a best practice for security, compatibility and accessing the latest features. Below are steps for updating PowerShell on different platforms.
Updating on Windows
- Visit the PowerShell GitHub page to download the latest version of PowerShell.
- Download the installer for your system architecture (x64 or x86).
- Run the installer and follow the prompts to complete the installation.
- After installation, open a new PowerShell window and use the $PSVersionTable command to verify the update.
Updating on macOS
- Open a terminal window.
- If PowerShell was installed using Homebrew, first run brew update to refresh Homebrew’s package database.
- Next, execute brew upgrade powershell to install the latest version of PowerShell.
- Verify the update by typing “pwsh –version” in the terminal. This will display the current version of PowerShell installed on your system.
Updating on Linux:
- Open a terminal window.
- For Debian-based systems like Ubuntu:
- Run sudo apt-get update to update your package lists.
- Then, execute sudo apt-get install -y powershell to install the latest version.
- For Red Hat-based systems like CentOS:
- Run sudo yum update powershell.
- Follow up with sudo yum install -y powershell.
- Confirm the update by typing “pwsh –version” in the terminal, which will display the current PowerShell version installed.
By regularly checking and updating your PowerShell installation, you can validate that you’re taking full advantage of the latest improvements while maintaining a secure and efficient IT environment. The version you use can significantly impact the features available to you, the security of your environment and the compatibility of your scripts.
NinjaOne can help IT administrators streamline their operations by automating repetitive tasks, such as PowerShell scripting, ensuring that networks function optimally and data remains secure. Discover how NinjaOne’s IT automation tools can save you time and enhance efficiency in your daily tasks. Try NinjaOne now for free.