How to Update Windows PowerShell to the Latest Version

  1. Updating Windows PowerShell 5.1
  2. Installing and Updating PowerShell (Core) 7
How to Update Windows PowerShell to the Latest Version

When running scripts in Windows PowerShell, we may encounter some errors because of the outdated PowerShell version. To check the Windows PowerShell version, we can type in $PSVersionTable in our scripting environment or run the syntax below.

Get-Host | Select-Object Version

We could get automatic updates from Windows Update in the past. Still, as Microsoft is slowly migrating to PowerShell (Core) 7.0 as its primary scripting version, PowerShell 5.1 is the last version that will be ever released.

This article will show you how to get updates on demand using Windows PowerShell.

Updating Windows PowerShell 5.1

Right now, given that Windows PowerShell 5.1 is in a maintenance-only mode, we will see no new significant development, unlike its recent successor, PowerShell (Core) 7 edition.

However, you can update the PowerShellGet module, in which the problem-causing Register-PSRepository command is defined. To update Windows PowerShell 5.1, run the following command below.

Update-Module PowerShellGet

While you usually would just run the command above, a different approach is required the first time when switching to the latest version from the PowerShell Gallery.

  • Open an elevated session (Run as Administrator).
  • Execute the following (add -Verbose to get detailed information):
Install-Module PowerShellGet -Force

The -Force enables installation even though a module by that name is already installed. Note that you may still see a prompt about downloading the NuGet package provider.

Note that the old PowerShellGet version will linger in a different location, but the new one will take precedence over it.

After this initial switch to the gallery-installed version, you’ll be able to use Update-Module PowerShellGet for future versions.

Installing and Updating PowerShell (Core) 7

Unlike Windows PowerShell 5.1, Windows PowerShell (Core) 7 doesn’t pre-load in Windows operating systems and requires manual installation. If you’re running Windows 10 operating systems and above, you can get PowerShell (Core) 7 in the Microsoft Store.

Alternatively, we can use the Windows Package Manager or winget command line to quickly discover, install, upgrade, remove and configure applications on Windows 10 computers.

The Windows Package Manager or winget is currently in preview. To install the preview of winget, you have two choices:

  • The command winget is open source, which technically means you can clone, build, and run the repository from Github.
  • You can also become a Windows Insider and join the Windows Package Manager Insider program by sending your Microsoft Account to winget-feedback@microsoft.com and requesting to be included in the preview.

After joining the Insider program, go to the Microsoft Store and get App Installer’s application. The Windows Package Manager or winget will be available after you get the update.

Now you can start using the Windows Package Manager or winget in the Windows Terminal, Windows CLI, or Windows PowerShell. The command-line client winget.exe is already pre-configured to point to the Microsoft community repository.

To check for all available PowerShell installers in the Windows Package Manager, run the command below.

winget search powershell

You can run the following command below to install the latest Windows PowerShell (Core) 7 version.

winget install powershell

You can also use winget to upgrade your current Windows PowerShell version.

winget upgrade powershell

Alternatively, you can use the following script below to get an updated Windows PowerShell package.

Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

Run the following command from the command prompt wait until it gets downloaded, and it will prompt to installation wizard to follow the instructions to install it.

Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.

LinkedIn