To update PowerShell via the command line, the exact steps can vary depending on the current version you're using and the target version you wish to upgrade to. PowerShell comes in two main flavors: Windows PowerShell and PowerShell Core (now just called PowerShell, starting with version 6).
For Windows PowerShell (Up to 5.1)
As of my last update in 2023, Windows PowerShell 5.1 is the latest (and final) version for the built-in Windows PowerShell. It comes pre-installed with Windows 10 and does not have an upgrade path via the command line to a newer version of PowerShell because there simply isn't a new version in the Windows PowerShell line. Instead, you would transition to PowerShell Core (version 6 and beyond) for newer features.
Upgrading to PowerShell Core (Version 6 and above)
PowerShell Core is built on top of .NET Core and is a cross-platform (Windows, Linux, and macOS) edition of PowerShell. It is updated and managed separately from the Windows PowerShell that comes with Windows itself.
Using the Command Line for Windows
-
Download and Install PowerShell Core via MSI Package (Windows):
- First, you might want to uninstall the previous version of PowerShell Core.
- Visit the GitHub releases page to find the download link for the
.msi installer of the latest version.
- You can then use
Invoke-WebRequest in your existing PowerShell to download the .msi file. For example:
Invoke-WebRequest -Uri "https://github.com/PowerShell/PowerShell/releases/download/v7.2.0/PowerShell-7.2.0-win-x64.msi" -OutFile "PowerShell-7.2.0-win-x64.msi"
- Then, use
msiexec to install PowerShell silently (without GUI interaction):
msiexec.exe /i PowerShell-7.2.0-win-x64.msi /qn
-
Via Winget (Windows Package Manager):
-
Using PowerShellGet for older versions of PowerShell Core:
- For upgrading from very old versions of PowerShell Core, you might use PowerShellGet if it was previously set up for such a purpose, though as of version 6 and later, direct use of installation packages or winget as shown above is more common.
On Linux or macOS
Linux and macOS updates for PowerShell Core generally involve using the package manager specific to the distribution you are running (like apt for Ubuntu or brew for macOS).
Example for Ubuntu:
# Update the list of products
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
Example for macOS (using Homebrew):
brew update
brew upgrade --cask powershell
Important Note
Always check the official PowerShell GitHub repository and documentation for the most current instructions, as URLs and processes can change. Keep your system's security in mind when downloading and installing software.