PowerShell 7, currently available in version 7.1, is the most recent release of Microsoft's cross-platform scripting language. Today, we will take a look at how to install and upgrade to PowerShell 7.1.

For many years, PowerShell was a Windows-only scripting language. However, this changed a couple of years ago with PowerShell Core 6. Microsoft has continued this cross-platform trend, and the latest release of PowerShell 7.1 is no different. It is built on .NET Core 3.1 and is supported on multiple platforms. More detailed information can be found on the PowerShell Support Lifecycle page.

PowerShell 7.1 supported platforms

PowerShell 7.1 supported platforms

PowerShell is now an open-source project located on GitHub. In this post, I will focus on how to install PowerShell 7.1 in a Windows-based environment. To install PowerShell 7.1 on different platforms, use the official Microsoft documentation for Linux, MacOS, and ARM.

Prerequisites ^

The only prerequisites mentioned in the documentation are related to PowerShell 7.1 remoting over WSMan. To use remoting over WSMan, the following prerequisites need to be met:

Note there is a little inconsistency in Microsoft's documentation. Whereas the PowerShell Support Lifecycle page says that Windows 7 and Windows Server 2008 R2 are not supported, the Installing PowerShell on Windows page says that PowerShell 7.1 is supported on those systems.

Documentation inconsistency about supported Windows systems

Documentation inconsistency about supported Windows systems

PowerShell 7.1 and earlier PowerShell versions ^

PowerShell 7 was designed to coexist with Windows PowerShell 5.1. PowerShell 7 installs to a new directory, enabling side-by-side execution.

PowerShell install locations can be found in the PATH variable:

  • Windows PowerShell 5.1: $env:WINDIR\System32\WindowsPowerShell\v1.0
  • PowerShell Core 6.x: $env:ProgramFiles\PowerShell\6
  • PowerShell 7: $env:ProgramFiles\PowerShell\7

The versions also have different executable names:

  • powershell.exe for Windows PowerShell 5.1
  • pwsh.exe for PowerShell 7/7.1

For more information, read PowerShell v5 vs. PowerShell v7—Which to use and when, written by my colleague, Timothy Warner, here on 4sysops.com.

Migration from PowerShell Core 6.x to PowerShell 7 is an in-place upgrade. PowerShell Core 6.x is replaced and its install location removed from the PATH variable.

Manual MSI package installation ^

To install PowerShell using the MSI package, simply download it from GitHub and follow the setup prompts. The installer comes with several options, such as Enable PowerShell remoting.

MSI package installation options

MSI package installation options

I mention Enable PowerShell remoting because in PowerShell 7.1, remoting over WSMan requires a different WinRM endpoint than Windows PowerShell 5.1. Also, the Enter-PSSession command needs to have a –ConfigurationName parameter specified; otherwise, the Windows PowerShell 5.1 remoting endpoint will be used.

Enter-PSSession -ComputerName dc -ConfigurationName "powershell.7.1.0"

However, be aware that this checkbox does not work and the installer will not perform the required actions. To enable remoting, you have to run script Install-PowerShellRemoting.ps1 located in the $PSHome folder. The picture below shows an attempt to access the server remotely after the MSI package installation and after the script execution.

MSI installer does not enable PowerShell 7.1 remoting

MSI installer does not enable PowerShell 7.1 remoting

Additional information about what the script does can be found in this article. It's a bit silly that Microsoft says "the installation script is a short-term solution, until we add the functionality to Enable-PSRemoting" in an article released in the middle of 2018, isn't it?

Command line MSI package installation ^

As usual, MSI packages can also be installed via the command line, allowing unattended installation. To silently install PowerShell 7.1, use the command below.

msiexec.exe /package "c:\Temp\PowerShell-7.1.0-win-x64.msi" /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1

Interestingly, using command line installation will also flawlessly enable PowerShell 7.1 remoting, unlike the graphical MSI installer. You can also install PowerShell 7.1 remotely via the PSExec tool. As you can see in the picture, PowerShell 7.1 remoting works fine immediately following the execution.

.\PsExec.exe \\srv msiexec.exe /package "c:\Temp\PowerShell-7.1.0-win-x64.msi" /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1
Install PowerShell 7.1 via PSExec

Install PowerShell 7.1 via PSExec

Alternatively, the installation can also be performed remotely using Windows PowerShell 5.1 remoting.

Invoke-Command -ComputerName srv -ScriptBlock {Start-Process msiexec.exe -ArgumentList '/package "c:\Temp\PowerShell-7.1.0-win-x64.msi" /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1' -Wait}

Be aware this method can be a bit tricky. It ends with an error, even if the installation was successful. The reason for the error is very simple. You are using remoting over WSMan, and since the installer is adding a new WSMan endpoint and restarts the WinRM service after that, your remoting session is terminated.

Error during PowerShell 7.1 installation over Windows PowerShell remoting session

Error during PowerShell 7.1 installation over Windows PowerShell remoting session

Notice that despite the error, I was able to connect to PowerShell 7 remoting right away, which means PowerShell 7.1 was installed successfully and its WSMan endpoint was created correctly.

New registry keys ^

Since PowerShell 7.1, the installer has created new registry keys that store the installation location and version. This may be used by administrators or developers to find out where PowerShell is located, as the installation path is no longer fixed. The GUID value is unique for each build type, major version, and architecture.

Registry keys store installation location and version

Registry keys store installation location and version

ZIP package installation ^

PowerShell 7.1 can also be deployed using ZIP packages. After downloading the package from GitHub, simply extract it to any location and run pwsh.exe. This method can be useful if you need to run PowerShell 7.1 side-by-side with other versions, such as PowerShell Core 6.x.

Note that deploying PowerShell from the ZIP package will not check the prerequisites needed for remoting over WSMan, it will not create registry keys with the installation location, and the WSMan remoting endpoint is not created.

One-liner script to install/update PowerShell 7.1 ^

Steve Lee from the Microsoft PowerShell team created a one-liner script to install and update PowerShell on Windows 10. From an elevated PowerShell session, run the following command:

Invoke-Expression "& { $(Invoke-RestMethod 'https://aka.ms/install-powershell.ps1') } –useMSI -EnablePSRemoting -Quiet"

There is also a script available to install PowerShell 7.1 on Linux.

wget https://aka.ms/install-powershell.sh; sudo bash install-powershell.sh; rm install-powershell.sh

Both scripts have several switches available, and their descriptions can be found directly in the scripts.

Subscribe to 4sysops newsletter!

Final words ^

In this post, we have taken a look at various ways to install PowerShell 7.1 in a Windows-based environment and how to enable and use PowerShell 7.1 remoting over WSMan. Don't get confused with the naming—Windows PowerShell goes with version 5.1, and PowerShell goes with version 7.1. Further details can be found in the official documentation.

avatar
9 Comments
  1. nice article. 
    i tried to run a module from a remote share and to my surprise it blocked the script, while the older 5.0 version of PowerShell does not block, under the same circumstances. (yes, i can get it to run in 7.x with bypass etc. but i prefer RemoteSigned, and the UNC path in trusted sites.)  

    avatar
  2. I am using the Microsoft Store version. I think that it'll be easier to update.

    avatar
  3. Nice article, thank you.  I had no idea about that remoting script. 

    David F. 

    avatar
  4. Ben H 1 year ago

    your update script is

    Invoke-Expression "& { $(Invoke-RestMethod 'https://aka.ms/install-powershell.ps1&#039😉 } useMSI -EnablePSRemoting -Quiet"

    you need a minus before the useMSI swtich

    -useMSI

  5. Francis Finan 3 months ago

    You can also use the following:

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

Leave a reply to Leos Marek (Rank: 4)
Click here to cancel the reply

Please enclose code in pre tags

Your email address will not be published.

*

© 4sysops 2006 - 2022

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account