๐ŸชŸWindows

PowerShell often comes installed with windows.

This article is adapted from a microsoft guide, link is: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4

Installing from the Microsoft Store

PowerShell can be installed from the Microsoft Store. You can find the PowerShell release in the Microsoft Store site or in the Store application in Windows.

Benefits of the Microsoft Store package:

  • Automatic updates built right into Windows

  • Integrates with other software distribution mechanisms like Intune and Configuration Manager

  • Can install on Windows systems using x86, x64, or Arm64 processors

Known limitations

By default, Windows Store packages run in an application sandbox that virtualizes access to some filesystem and registry locations. Changes to virtualized file and registry locations don't persist outside of the application sandbox.

This sandbox blocks all changes to the application's root folder. Any system-level configuration settings stored in $PSHOME can't be modified. This includes the WSMAN configuration. This prevents remote sessions from connecting to Store-based installs of PowerShell. User-level configurations and SSH remoting are supported.

The following commands need write to $PSHOME. These commands aren't supported in a Microsoft Store instance of PowerShell.

  • Register-PSSessionConfiguration

  • Update-Help -Scope AllUsers

  • Enable-ExperimentalFeature -Scope AllUsers

  • Set-ExecutionPolicy -Scope LocalMachine

For more information, see Understanding how packaged desktop apps run on Windows.

Changes for PowerShell 7.2

Beginning in PowerShell 7.2, the PowerShell package is now exempt from file and registry virtualization. Changes to virtualized file and registry locations now persist outside of the application sandbox. However, changes to the application's root folder are still blocked.

You must be running on Windows build 1903 or higher for this exemption to work.

Installing a preview version

Preview releases of PowerShell 7 install to $env:ProgramFiles\PowerShell\7-preview so they can be run side-by-side with non-preview releases of PowerShell. PowerShell 7.4 is the next preview release.

Upgrading an existing installation

For best results when upgrading, you should use the same install method you used when you first installed PowerShell. If you aren't sure how PowerShell was installed, you can check the value of the $PSHOME variable, which always points to the directory containing PowerShell that the current session is running.

  • If the value is $HOME\.dotnet\tools, PowerShell was installed with the .NET Global tool.

  • If the value is $Env:ProgramFiles\PowerShell\7, PowerShell was installed as an MSI package or with Winget on a computer with an X86 or x64 processor.

  • If the value starts with $Env:ProgramFiles\WindowsApps\, PowerShell was installed as a Microsoft Store package or with Winget on computer with an ARM processor.

  • If the value is anything else, it's likely that PowerShell was installed as a ZIP package.

If you installed via the MSI package, that information also appears in the Programs and Features Control Panel.

To determine whether PowerShell may be upgraded with Winget, run the following command:

winget list --name PowerShell --upgrade-available

If there is an available upgrade, the output indicates the latest available version.

When upgrading, PowerShell won't upgrade from an LTS version to a non-LTS version. It only upgrades to the latest version of LTS, for example, from 7.2.3 to 7.2.16. To upgrade from an LTS release to a newer stable version or the next LTS, you need to install the new version with the MSI for that release.

When the installed version isn't an LTS version, PowerShell upgrades to the latest stable version.

Deploying on Windows 10 IoT Enterprise

Windows 10 IoT Enterprise comes with Windows PowerShell, which we can use to deploy PowerShell 7.

# Replace the placeholder information for the following variables:
$deviceip = '<device ip address'
$zipfile = 'PowerShell-7.4.0-win-arm64.zip'
$downloadfolder = 'u:\users\administrator\Downloads'  # The download location is local to the device.
# There should be enough  space for the zip file and the unzipped contents.

# Create PowerShell session to target device
Set-Item -Path WSMan:\localhost\Client\TrustedHosts $deviceip
$S = New-PSSession -ComputerName $deviceIp -Credential Administrator
# Copy the ZIP package to the device
Copy-Item $zipfile -Destination $downloadfolder -ToSession $S

#Connect to the device and expand the archive
Enter-PSSession $S
Set-Location u:\users\administrator\Downloads
Expand-Archive .\PowerShell-7.4.0-win-arm64.zip

# Set up remoting to PowerShell 7
Set-Location .\PowerShell-7.4.0-win-arm64
# Be sure to use the -PowerShellHome parameter otherwise it tries to create a new
# endpoint with Windows PowerShell 5.1
.\Install-PowerShellRemoting.ps1 -PowerShellHome .

When you set up PowerShell Remoting you get an error message and are disconnected from the device. PowerShell has to restart WinRM. Now you can connect to PowerShell 7 endpoint on device.

# Be sure to use the -Configuration parameter. If you omit it, you connect to Windows PowerShell 5.1
Enter-PSSession -ComputerName $deviceIp -Credential Administrator -Configuration PowerShell.7.4.0

Deploying on Windows 10 IoT Core

Windows 10 IoT Core adds Windows PowerShell when you include IOT_POWERSHELL feature, which we can use to deploy PowerShell 7. The steps defined above for Windows 10 IoT Enterprise can be followed for IoT Core as well.

For adding the latest PowerShell in the shipping image, use Import-PSCoreRelease command to include the package in the workarea and add OPENSRC_POWERSHELL feature to your image.

For ARM64 architecture, Windows PowerShell isn't added when you include IOT_POWERSHELL. So the zip based install doesn't work. You need to use Import-PSCoreRelease command to add it in the image.

Deploying on Nano Server

These instructions assume that the Nano Server is a "headless" OS that has a version of PowerShell already running on it. For more information, see the Nano Server Image Builder documentation.

PowerShell binaries can be deployed using two different methods.

  1. Offline - Mount the Nano Server VHD and unzip the contents of the zip file to your chosen location within the mounted image.

  2. Online - Transfer the zip file over a PowerShell Session and unzip it in your chosen location.

In both cases, you need the Windows x64 ZIP release package. Run the commands within an "Administrator" instance of PowerShell.

Offline Deployment of PowerShell

  1. Use your favorite zip utility to unzip the package to a directory within the mounted Nano Server image.

  2. Unmount the image and boot it.

  3. Connect to the built-in instance of Windows PowerShell.

  4. Follow the instructions to create a remoting endpoint using the "another instance technique".

Online Deployment of PowerShell

Deploy PowerShell to Nano Server using the following steps.

# Replace the placeholder information for the following variables:
$ipaddr = '<Nano Server IP address>'
$credential = Get-Credential # <An Administrator account on the system>
$zipfile = 'PowerShell-7.4.0-win-x64.zip'
# Connect to the built-in instance of Windows PowerShell
$session = New-PSSession -ComputerName $ipaddr -Credential $credential
# Copy the file to the Nano Server instance
Copy-Item $zipfile c:\ -ToSession $session
# Enter the interactive remote session
Enter-PSSession $session
# Extract the ZIP file
Expand-Archive -Path C:\PowerShell-7.4.0-win-x64.zip -DestinationPath 'C:\Program Files\PowerShell 7'

If you want WSMan-based remoting, follow the instructions to create a remoting endpoint using the "another instance technique".

Last updated