Skip to content

Maintaining PowerShell

Summary

Instructions for installing and updating PowerShell, help files and modules.

Notes:

  • These tasks can take a few minutes, especially on older machines.
  • Windows PowerShell 5.1 is still required for some legacy scripts, modules and Windows administration tasks.
  • Most modern scripts, commands and modules are now written for PowerShell 7.
  • PowerShell 7 installs side-by-side with Windows PowerShell 5.1.
  • Windows PowerShell 5.1 uses powershell.exe.
  • PowerShell 7 uses pwsh.exe.

Requirements

Check that winget is available:

winget --version

Search for available PowerShell packages:

winget search Microsoft.PowerShell

Installing PowerShell

Windows PowerShell 5.1

Windows PowerShell 5.1 is the legacy built-in Windows version of PowerShell. It is installed by default on Windows 10, Windows 11, Windows Server 2016 and newer.

Check the installed Windows PowerShell version:

$PSVersionTable.PSVersion

Launch Windows PowerShell 5.1:

powershell.exe

Install or repair Windows PowerShell 5.1

On modern supported Windows versions, PowerShell 5.1 is part of Windows and is not normally installed using winget.

For older supported systems, Windows PowerShell 5.1 is installed through Windows Management Framework 5.1, not the normal PowerShell 7 winget package.

Important:

winget install Microsoft.PowerShell installs PowerShell 7, not Windows PowerShell 5.1.


PowerShell 7

PowerShell 7 is the modern, cross-platform version of PowerShell. It runs side-by-side with Windows PowerShell 5.1 and is the recommended version for most modern automation tasks.

Install PowerShell 7 using winget:

winget install --id Microsoft.PowerShell --source winget

Install PowerShell 7 Preview:

winget install --id Microsoft.PowerShell.Preview --source winget

Launch PowerShell 7:

pwsh

Check the installed PowerShell 7 version:

$PSVersionTable.PSVersion

Updating PowerShell

Update PowerShell 7 using winget

Update PowerShell 7:

winget upgrade --id Microsoft.PowerShell

Update PowerShell 7 Preview:

winget upgrade --id Microsoft.PowerShell.Preview

Update all available winget packages:

winget upgrade --all

Check installed PowerShell packages:

winget list Microsoft.PowerShell

Update-Module

Update all installed PowerShell modules:

Update-Module

Update all installed PowerShell modules without prompting for confirmation:

Update-Module -Force

Update a specific PowerShell module:

Update-Module -Name modulename

Full syntax for Update-Module:

Update-Module
      [[-Name] <String[]>]
      [-RequiredVersion <String>]
      [-MaximumVersion <String>]
      [-Credential <PSCredential>]
      [-Scope <String>]
      [-Proxy <Uri>]
      [-ProxyCredential <PSCredential>]
      [-Force]
      [-AllowPrerelease]
      [-AcceptLicense]
      [-PassThru]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Update-Help

Update PowerShell help files:

Update-Help

Update PowerShell help files without prompting for confirmation:

Update-Help -Force

Update help files for a specific module:

Update-Help -Module Microsoft.PowerShell.Management -Force

Full syntax for Update-Help:

Update-Help
      [[-Module] <String[]>]
      [-FullyQualifiedModule <ModuleSpecification[]>]
      [[-SourcePath] <String[]>]
      [-Recurse]
      [[-UICulture] <CultureInfo[]>]
      [-Credential <PSCredential>]
      [-UseDefaultCredentials]
      [-Force]
      [-Scope <UpdateHelpScope>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Useful Version Checks

Check the current PowerShell version:

$PSVersionTable

Check PowerShell executable paths:

Get-Command powershell.exe
Get-Command pwsh.exe

Check installed modules:

Get-InstalledModule

Check available modules:

Get-Module -ListAvailable

Microsoft PowerShell 7 installation article

Microsoft Windows PowerShell 5.1 article

Microsoft Windows Management Framework article

Microsoft winget article

Microsoft Update-Module article

Microsoft Update-Help article