Keeping your PowerShell version up-to-date makes sure that you can use the latest features and cmdlets in your scripts. But how do you update PowerShell?
There are two versions of PowerShell at the moment, Windows PowerShell 5.1 and PowerShell Core (7.x). Most modules are switching over to PowerShell 7, but 5.1 is still mainly used. Luckily we can use those two versions next to each other.
In this article
In this article, I will explain how you can update both versions of PowerShell, and how to install/upgrade to PowerShell 7. If you are unsure which version you are currently using, then check this article on how to view your PowerShell version.
Update PowerShell 5.1
PowerShell 5.1 is still the most commonly used and installed PowerShell version at the moment. If you open the Terminal or PowerShell on a Windows 10/11 computer or Windows Server 2016 and newer and type in $PSVersionTable
then you will see that version 5.1 (1)
is installed.
The version number exists out of 4 parts:
Major | Minor | Build | Revision |
---|---|---|---|
5 | 1 | 22621 | 963 |
If you check the PowerShell version on another machine, then you might have noticed that the build and revision numbers are different. Now you might think, how can I update PowerShell so the build numbers match?
The problem here is that PowerShell 5.1 is part of the Windows Management Framework 5.1 and is updated automatically with your Windows Updates. As we can see in the screenshot above, the build and revision numbers match the Build Version of the OS (2)
.
Good to know is that PowerShell 5.x isn’t developed anymore. The latest version is 5.1 and there won’t be any updates for it anymore. PowerShell Core 7.x is the successor of PowerShell 5.1.
Update from older PowerShell versions
On older operating systems, like Windows Server 2012 R2, you can still find PowerShell 4 installed. PowerShell 3 and 4 can be updated to PowerShell 5.1. To do this we will need to install the Windows Management Framework 5.1, which you can download here at Microsoft. The following operating systems are supported:
- Windows Server 2012 R2
- Windows Server 2012
- Windows Server 2008 R2 SP1
- Windows 8.1
- Windows 7 SP1
Make sure that you select the correct version of your OS and that have installed .Net Framework 4.5 or higher.
After the installation, you will need to reboot the computer to use the new PowerShell version.
Upgrade PowerShell
PowerShell Core 7, commonly revert to as PowerShell 7, is a completely new version of PowerShell. One of the biggest differences is that it not only can be used on Windows but also on macOS or Linux for example. This means that we cannot upgrade PowerShell 5.1 to 7, but instead, we can install PowerShell 7 next to version 5.1.
This way you can use both versions simultaneously on a single computer, which is a good thing. Because not all modules and cmdlets are available in PowerShell 7. So before you can fully switch over to the new version, you will need to do a lot of testing to make sure that all your script keep working.
To install PowerShell 7 we have a couple of options:
- WinGet – The built-in package manager in Windows 10 and 11
- MSI Installer – Best option for Windows Servers
- Microsoft Store
- Dev Home – Currently in preview, but allows you to easily install all required packages on your dev machine. Read more about Dev Home in this article.
Using WinGet to Install PowerShell 7
WinGet is a built-in command line tool in Windows that allows you to install packages on your Windows 10 or 11 computer. The advantage of WinGet is that you only need to run a single command to install a package.
At the moment there are two versions available of PowerShell 7, the stable version and a preview version. I recommend installing the stable version in production environments. To view the available versions you can run the following command:
winget search Microsoft.PowerShell # Result Name Id Version Source --------------------------------------------------------------- PowerShell Microsoft.PowerShell 7.3.4.0 winget PowerShell Preview Microsoft.PowerShell.Preview 7.4.0.3 winget
To install PowerShell 7 run the following command:
winget install --id Microsoft.Powershell --source winget
Winget will download the package after which the MSI installer will start:
Using the MSI
The Windows Package Manager (Winget) downloads the latest MSI file automatically. If you can’t or don’t want to use WinGet, then you can also download the MSI file manually from the PowerShell GitHub page. Another (easier) option is to use the download link here in the Microsoft documentation.
- Open the PowerShell GitHub Page
- Click on the latest Release version in the right sidebar
- Scroll all the way down on the release page
- Download the latest PowerShell-7.x.x-win-x64.msi file
Open the MSI after it’s downloaded. We have a couple of options that we can enable. I recommend installing all options from the installer:
On the next page, leave both updating options enabled. This way you will always have the latest stable version of PowerShell 7 installed on your computer.
Install with Microsoft Store
Personally, I don’t use the Microsoft Store much, but it’s possible to install PowerShell through the store. Simply open the Store and search for PowerShell 7. Make sure you select PowerShell and not the PowerShell Preview version and click on Get.
Using PowerShell 7
PowerShell 7 is a different app/console than PowerShell 5.1. If you open Terminal or PowerShell from the start menu and run the command $PSVersionTable
, then you will see that the version number is still 5.1. This is normal because you are actually using PowerShell 5.1 at that moment.
To use PowerShell 7, you have two options:
- Open it from the Start Menu
- Open it through Terminal > New Tab
To open it from the start menu, just search for the PowerShell 7 app. This will open the new version in the terminal app.
Another option is to use the built-in Windows Terminal. If you click on the drop-down arrow (1)
next to the new tab icon, then you can select PowerShell, which is PowerShell 7. We can also change the default PowerShell version in Terminal to PowerShell 7.
Click on the drop-down arrow (1)
, choose Settings, and change the default profile (2)
to PowerShell.
If you run the command $PSVersionTable
in the new PowerShell console, then you will see that the PSVersion is set to 7.x.x
and the PSEdition is Core:
Update PowerShell 7 Command
PowerShell Core 7 is being actively developed at the moment. A new release comes out pretty much every month. Now PowerShell 7 should update with your Windows Updates if you have version 7.2 or higher. But we can also manually update PowerShell with a single command to the latest version. For this, we will be using the command-line tool WinGet.
To view which version you have currently installed you can use the WinGet List
command below:
winget list --id Microsoft.Powershell # Result Name Id Version Available Source -------------------------------------------------------------- PowerShell 7-x64 Microsoft.PowerShell 7.3.2.0 7.3.4.0 winget
As you see in the results above, PowerShell version 7.3.2 is currently installed. Also, the latest available version is listed, which is at the moment of writing, version 7.3.4. To update PowerShell we can use the upgrade
parameter in Winget:
winget upgrade --id Microsoft.Powershell
After the upgrade is complete you will need to reload the console to use the new version.
Wrapping Up
Keeping PowerShell 7 up-to-date is important to make sure that your scripts work on all device. However, PowerShell 5.1, won’t receive any updates anymore, but is still mainly used. Personally I try to write most of my new scripts in PowerShell 7 when possible. This will make them future prove.
I hope this articled helped you with updating PowerShell. If you have any questions or tips, just drop a comment below.
Thank you for the article!