Computer >> Computer tutorials >  >> System >> Windows Server

Updating PowerShell Version on Windows

In this article, we will show how to update your Windows PowerShell version to the latest 5.1 and install (upgrade to) PowerShell Core 7.1. In the previous article, we told that there are currently two versions of PowerShell: a classic Windows PowerShell (the latest version is 5.1 and it is no longer developed) and a new PowerShell Core platform (version 7.1 is available now). Despite that the PowerShell version numbering goes on from 5.1 (6.0, 6.1, 7.0, 7.1, etc.), these are two different platforms. So, we’ll show how to update both Windows PowerShell and PowerShell Core.

Contents:

  • Upgrading to Windows PowerShell 5.1
  • How to Install or Update to PowerShell Core 7?
  • Installing PowerShell Core via Microsoft Store
  • Deploying PowerShell Core with Group Policy
  • Updating PowerShell Remotely

Upgrading to Windows PowerShell 5.1

PowerShell 4.0 is installed by default on Windows Server 2012 R2 (Windows 8.1). Let’s try to update the Windows PowerShell version to 5.1 on Windows Server 2012 R2.

First of all, check the current PowerShell version (the screenshot shows PowerShell 4.0 is installed):

$PSVersionTable.PSVersion

Updating PowerShell Version on Windows

To upgrade your PowerShell version to 5.1, install the Windows Management Framework 5.1, which requires the .NET Framework 4.5.2 (or newer). Make sure that .NET 4.5.2 or higher is installed using this command:

(Get-ItemProperty ‘HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full’ -Name Release).Release

Updating PowerShell Version on Windows

In my case, the release version 378675 means that .NET Framework version 4.5.1 is installed. So, I have to download and install the latest .NET Framework 4.8 (here is the link to the offline installer: https://go.microsoft.com/fwlink/?linkid=2088631 — ndp48-x86-x64-allos-enu.exe).

Install the .NET 4.8 (you will have to reboot your computer):

Updating PowerShell Version on Windows

If you install WMF 5.1 without .NET 4.5.2, some PowerShell features will not be available.

Download WMF 5.1 for Windows Server 2012 R2 — Win8.1AndW2K12R2-KB3191564-x64.msu (https://go.microsoft.com/fwlink/?linkid=839516).

Install the Windows Management Framework 5.1 MSU file.

Updating PowerShell Version on Windows

After the server restart, open the PS console and make sure that the PowerShell version has been updated to 5.1.

Updating PowerShell Version on Windows

If you have unsupported Windows 7 or Windows Server 2008 R2, you can upgrade the PowerShell version from 2.0 to 5.1 in the same way. First, install .Net Framework 4.5.2 (or newer), then WMF 5.1 (the download links will be different from those for Windows Server 2012 R2).

How to Install or Update to PowerShell Core 7?

Note that the latest Windows PowerShell version installed in Windows 10 and Windows Server 2019 is PowerShell 5.1. Microsoft started to develop a cross-platform PowerShell Core version instead. Currently, PowerShell Core 6.0, 6.1, 6.2, 7.0 and 7.1 are available. PowerShell Core is essentially a new platform that is installed on the computer along with Windows PowerShell. It means that you cannot upgrade PowerShell 5.1 to PowerShell Core 7.1. PowerShell 7 is installed on a computer separately from Windows PowerShell 5.1.

In PowerShell 7.1, the developers added maximum compatibility with Windows PowerShell. So, you can easily run your old PS1 scripts and cmdlets in PowerShell Core.  

If you have PowerShell Core 6.0 installed, you can update the PowerShell version on your computer to the latest PowerShell 7.1 Core (or you can install PowerShell Core 7.1 together with Windows PowerShell 5.1). In this example, we will try to update PowerShell Core in Windows 10 20H2. There are two ways to upgrade:

  • You can download the PowerShell Core MSI installer manually from GitHub;
  • You can download and install (update) it directly from the PowerShell console.
The latest releases of PowerShell Core can be installed on all versions of Windows starting with Windows 7 SP1, Server 2008 R2, and newer.

If you want to install PowerShell Core using the MSI package, go to the project page https://github.com/PowerShell/PowerShell, find the latest stable release. At the time of this writing, this is the March 4, 2021 release of PowerShell v7.1.3. The higher preview Release of PowerShell v7.2.0 is also available, but you’d better wait for a more stable version. Expand the Assets list and find a package for your Windows version (PowerShell-7.1.3-win-x64.msi or PowerShell-7.1.3-win-x86.msi).

Updating PowerShell Version on Windows

 

Download the MSI file and install it.

Updating PowerShell Version on Windows

To install PowerShell Core from an MSI package using SCCM/MDT/scripts in quiet mode, you can use a command with the following parameters:

msiexec.exe /package PowerShell-7.1.0-win-x86.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1

You can update the PowerShell right from the PS cli.

Let’s update (install) the latest PowerShell Core version using the command:

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

This command downloads the PowerShell 7.1 MSI distribution file from GitHub and then starts the installation via the MSI installer.

You can also use other installation parameters:

  • -Destination – change the default PowerShell Core installation folder
  • -Preview – install the latest Preview PowerShell version
  • -Quiet – a quiet installation mode
  • -AddToPath – adds a path to the PowerShell Core installation directory to the environment variables

Updating PowerShell Version on Windows

After the installation is finished, the PowerShell Core (pwsh.exe) window appears. Check the PowerShell version here to make sure it is PoSh 7.1.3.

Updating PowerShell Version on Windows

If you have the WinGet package manager installed, you can install or update your PowerShell version to the latest command:

winget install --id=Microsoft.PowerShell -e

Or, you can install a specific version of PowerShell Core:

winget install --id=Microsoft.PowerShell -v "7.1.2" -e

If you have Chocolatey package manager installed, use the commands:

choco install powershell -y
choco upgrade powershell -y

or for PowerShell 7.x:
choco install pwsh -y
choco install pwsh -y

Pay attention to the directories of different PowerShell versions:

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

If PowerShell 6.x was installed on your computer, the $env:ProgramFiles\PowerShell\6 directory is automatically removed when you install PowerShell 7.1.

Note that the name of the PowerShell executable has changed. In PowerShell Core it is c:\Program Files\PowerShell\7\pwsh.exe. It has its own icon in the Start menu.

  • To run .NET Framework-based Windows PowerShell, the powershell.exe command is used
  • To run .NET Core-based PowerShell Core, use the pwsh.exe

Updating PowerShell Version on Windows

This means that you have both Windows PowerShell 5.1 and PowerShell Core 7.1 installed on your computer.

Updating PowerShell Version on Windows

In order to find out the version and build of PowerShell installed on your device, you can check the version of the pwsh.exe file:

(Get-Command 'C:\Program Files\PowerShell\7\pwsh.exe').Version

Updating PowerShell Version on Windows

This is how you can check the version of a file on a remote computer:

Invoke-Command -Computername computer1 -Scriptblock {(Get-Command 'C:\Program Files\PowerShell\7\pwsh.exe').Version}

Windows PowerShell provides a special backward compatibility mode that allows you to run an older version of PowerShell even if you have newer versions installed. You can start PowerShell of a specific version (for example 4.0) with the following command:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 4

Installing PowerShell Core via Microsoft Store

On Windows 10, you can install or update PowerShell via the Microsoft Store. You can manually find the PowerShell app in the Store or use this link. The advantage of this installation method is that the Store app will track the installed version of PowerShell and automatically install app updates as they become available.

But there are also disadvantages to the fact that such a PowerShell instance will run in a sandbox.

Updating PowerShell Version on Windows

You can download the APPX/MSIX application file and install it using the Add-AppxPackage cmdlet (or as described in the article “Repairing Microsoft Store”).

Deploying PowerShell Core with Group Policy

In the Active Directory domain, you can centrally deploy and update PowerShell Core using Group Policy. Use the GPO’s features to install MSI packages.

  1. Download the PowerShell MSI installation file and copy it to the SYSVOL directory on the domain controller;
  2. Open the Domain Group Policy Management Console (gpmc.msc), create a new GPO and link it to the OU with computers and servers;
  3. Go to the GPO section Computer Configuration -> Software Settings, create a new package, and specify the path to the PowerShell MSI installation file in the SYSVOL folder in the domain (use the UNC path); Updating PowerShell Version on Windows You can use the GPO WMI filters to more accurately target your policy to domain devices.
  4. To update the software installation Group Policy settings, you need to restart the computers. The new version of PowerShell will be installed on all computers at startup.

Updating PowerShell Remotely

You can use one of the following methods to update PowerShell on remote computers via the command prompt.

The first method allows you to remotely update PowerShell on the computer using the MSI installer in the shared network folder:

Invoke-Command -ComputerName mun-srv01 -ScriptBlock {Start-Process msiexec.exe -ArgumentList '/package "\\mun-fs01\install\PowerShell-7.1.3-win-x64.msi" /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1' -Wait}

The following script will select all active Windows 10 computers from the Active Directory domain and start downloading and installing PowerShell Core on each of them:

To use the GetADComputer cmdlet, the Active Directory PowerShell module must be installed on your device.
$ADComputers = Get-ADComputer -Filter 'operatingsystem -like "*Windows 10*" -and enabled -eq "true"'
ForEach ($computer in $ADcomputers) {
Invoke-Command -ComputerName $computer {iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"}
}

Be careful when using the PowerShell Remoting commands when connecting to remote computers (with the Enter-PSSession and Invoke-Command cmdlets). If you need to connect to a PowerShell 7.1 endpoint, you need to use the command:

Enter-PSSession -ComputerName dc01 -ConfigurationName "powershell.7.1.3"

Otherwise, you will connect to the PowerShell Remoting 5.1 endpoint.