Command Line to Update PowerShell 7 in Windows 11/10

PowerShell 7 is a powerful cross-platform shell and scripting language that enables developers and IT professionals to automate tasks and manage configurations. As a developer or administrator, keeping your tools up to date is crucial for taking advantage of the latest features, security updates, and performance improvements. In this guide, we will show you how to install or update PowerShell 7 using command line.

What is PowerShell 7? PowerShell 7, the successor to PowerShell Core 6.x and Windows PowerShell 5.1, brings forward significant enhancements. It not only bridges the gap between Windows PowerShell and PowerShell Core but also expands the capabilities of the shell and scripting language, making it an essential upgrade for developers and system administrators.

Update PowerShell 7 in Windows 11 with command line

Installing PowerShell 7 using “winget”

To install PowerShell 7 on your system using the command line, you have a couple of options. One of the most convenient methods is using the Windows Package Manager (winget), which is a tool designed to help you discover, install, upgrade, and configure applications on your Windows 10 or later computer.

  1. Open a command prompt or PowerShell window with administrative privileges.
  2. Type the following command and press Enter:
    winget install PowerShell

    Install or Update PowerShell 7 in Windows 11

  3. It will then prompt you to agree to the terms before installation. Press Y to continue.update powershell 7
  4. The winget tool will handle the rest, downloading and installing the latest version of PowerShell 7.

Note: If the winget command is not recognized, ensure that you have the Windows Package Manager installed. It comes pre-installed on Windows 10 version 1809 and later, as well as on Windows 11. If it’s not installed, you can get it from the Microsoft Store or from the GitHub releases page of the Windows Package Manager CLI (https://github.com/microsoft/winget-cli). Or, you can use the second method described below.

Related resource: Install Active Directory Users and Computers via PowerShell

Installing or updating PowerShell 7 using a simple script

If you have issue running winget or if you prefer another method instead, there’s a convenient script provided by Microsoft that can be used to install or update PowerShell 7. This method is particularly useful for automating updates or ensuring consistency across multiple machines. To use this script, run the following command in a PowerShell window:

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

Command line to update PowerShell 7 in Windows 11

Detailed explanation of what this script does

The command line might look complex at first glance, but it’s actually quite simple when broken down:

  • iex: Short for Invoke-Expression, this cmdlet is used to run commands or expressions passed to it as a string. In this case, it’s used to execute the installation script.
  • irm: This is an alias for Invoke-RestMethod, a cmdlet that sends an HTTP or HTTPS request to a web service and returns the response. Here, it’s used to download the PowerShell installation script from the provided URL (https://aka.ms/install-powershell.ps1).
  • & { ... }: This is a script block, a collection of statements or expressions that can be executed as a single unit. The & operator is used to execute the script block.
  • -UseMSI: This parameter tells the installation script to use the MSI (Microsoft Installer) package for installation. MSI packages are standard for Windows applications and provide a familiar installation experience, including options for silent installation, custom install locations, and more.

When this command is executed, it performs the following steps:

  1. Downloads the PowerShell installation script from the specified URL.
  2. Executes the script, which checks for the latest version of PowerShell.
  3. If a newer version is available, the script downloads and invokes the MSI installer.
  4. The MSI installer then updates PowerShell to the latest version, preserving your settings and configurations.

This method is especially useful for automated scripts or when managing multiple machines, as it can be included in deployment scripts or scheduled tasks to ensure PowerShell is always up to date.

Getting PowerShell 7 from Microsoft Store

Another convenient way of installing or keeping PowerShell 7 up-to-date is through the Microsoft Store. When installed from the Store, PowerShell 7 is automatically updated in the background, similar to how other store apps receive updates.

To install PowerShell from the Microsoft Store:

  1. Go to the Start menu and open the Microsoft Store.
  2. Use the Search feature and type “PowerShell”.
  3. Look for “PowerShell” from the results and click on the application.
  4. Click the “Get” or “Install” button and follow the prompts.Microsoft Store Install Windows PowerShell 7

Using the Microsoft Store for PowerShell updates offers the convenience of automatic updates, ensuring that you’re always running the latest version without manual intervention. It’s a great option for users who prefer a more graphical interface for managing their applications.

Verifying the installation

After installing or updating PowerShell, it’s a good practice to verify the installation. Use these steps to check your PowerShell version:

  1. Open a new PowerShell window.
  2. Type $PSVersionTable.PSVersion and press Enter.
  3. The displayed version number should match the latest version of PowerShell 7 you just installed or updated.Check PowerShell 7 version

Some common issues you might encounter

When updating PowerShell 7 via the command line, you may encounter issues. Here are a few tips:

  • If the winget command fails, make sure you are running the latest version of the Windows Package Manager.
  • If the script method gives an error, confirm that your PowerShell session has the necessary permissions to run scripts with the Set-ExecutionPolicy cmdlet.
  • When using the Microsoft Store, ensure you’re logged in with your Microsoft account and that the Store app is updated.

Final thoughts

In most cases, using the command line iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI" to update or install PowerShell 7 is highly recommended. This approach is favored because it grants more control over the installation process, making it ideal for developers and IT professionals who manage multiple machines or need to automate setups. The script ensures you’re always getting the latest version directly from Microsoft, with the added flexibility of using MSI options for custom installations. It’s efficient, straightforward once you understand the command structure, and integrates seamlessly into scripts for batch deployments or automated updates.

Remember to verify your installation after updating and consult the official PowerShell documentation for any troubleshooting needs.