banner



How To Update Powershell Through Powershell

PowerShell 7, currently available in version vii.1, is the well-nigh contempo release of Microsoft'south cross-platform scripting language. Today, we will accept a wait at how to install and upgrade to PowerShell vii.ane.

  • Author
  • Recent Posts

For many years, PowerShell was a Windows-simply scripting language. However, this inverse a couple of years agone with PowerShell Core 6. Microsoft has connected this cross-platform trend, and the latest release of PowerShell 7.1 is no different. It is congenital on .NET Core iii.1 and is supported on multiple platforms. More detailed information can be plant on the PowerShell Support Lifecycle folio.

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.i in a Windows-based environment. To install PowerShell 7.i on dissimilar platforms, apply 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 post-obit prerequisites need to be met:

  • Universal C runtime—Already included in Windows 10 and Windows Server 2016/2019
  • Windows Direction Framework (WMF) four.0 or newer—Required on Windows 7 or Windows Server 2008 R2

Note at that place is a little inconsistency in Microsoft's documentation. Whereas the PowerShell Back up Lifecycle folio says that Windows vii 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 well-nigh supported Windows systems

PowerShell 7.1 and before PowerShell versions ^

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

PowerShell install locations tin be found in the PATH variable:

  • Windows PowerShell v.i: $env:WINDIR\System32\WindowsPowerShell\v1.0
  • PowerShell Core 6.x: $env:ProgramFiles\PowerShell\vi
  • PowerShell 7: $env:ProgramFiles\PowerShell\seven

The versions also take different executable names:

  • powershell.exe for Windows PowerShell 5.i
  • pwsh.exe for PowerShell 7/vii.ane

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

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

Manual MSI bundle installation ^

To install PowerShell using the MSI packet, simply download information technology 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.i remoting endpoint will be used.

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

However, be enlightened that this checkbox does not work and the installer volition 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 subsequently the MSI packet installation and after the script execution.

MSI installer does not enable PowerShell 7.1 remoting

MSI installer does not enable PowerShell seven.1 remoting

Additional information near what the script does can be found in this article. It's a bit empty-headed 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?

Control line MSI package installation ^

As usual, MSI packages can also be installed via the command line, allowing unattended installation. To silently install PowerShell vii.1, utilise the control below.

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

Interestingly, using control line installation will also flawlessly enable PowerShell 7.i remoting, dissimilar the graphical MSI installer. You can too install PowerShell 7.1 remotely via the PSExec tool. As yous can see in the flick, PowerShell 7.i remoting works fine immediately post-obit the execution.

.\PsExec.exe \\srv msiexec.exe /package "c:\Temp\PowerShell-7.i.0-win-x64.msi" /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=one REGISTER_MANIFEST=1        

Install PowerShell 7.1 via PSExec

Install PowerShell 7.1 via PSExec

Alternatively, the installation can also exist performed remotely using Windows PowerShell 5.ane remoting.

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

Be enlightened this method tin exist a bit tricky. It ends with an error, even if the installation was successful. The reason for the error is very uncomplicated. You are using remoting over WSMan, and since the installer is adding a new WSMan endpoint and restarts the WinRM service afterward 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 correct away, which means PowerShell 7.1 was installed successfully and its WSMan endpoint was created correctly.

New registry keys ^

Since PowerShell seven.i, 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 stock-still. 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

Nothing package installation ^

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

Note that deploying PowerShell from the Goose egg parcel will not check the prerequisites needed for remoting over WSMan, information technology will non create registry keys with the installation location, and the WSMan remoting endpoint is non created.

One-liner script to install/update PowerShell 7.1 ^

Steve Lee from the Microsoft PowerShell team created a 1-liner script to install and update PowerShell on Windows ten. From an elevated PowerShell session, run the post-obit command:

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

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 tin be institute direct in the scripts.

Subscribe to 4sysops newsletter!

Final words ^

In this post, nosotros take taken a look at various ways to install PowerShell seven.i in a Windows-based environs and how to enable and use PowerShell 7.1 remoting over WSMan. Don't get dislocated with the naming—Windows PowerShell goes with version v.1, and PowerShell goes with version 7.1. Farther details can be establish in the official documentation.

avatar

Source: https://4sysops.com/archives/how-to-install-and-upgrade-to-powershell-71/

Posted by: richardsheith1954.blogspot.com

0 Response to "How To Update Powershell Through Powershell"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel