TExcelTAD
Home › PowerShell › PowerShell Install

PowerShell Install

PowerShell 7 is free and open source. It installs next to Windows PowerShell 5.1 instead of replacing it, so nothing on your computer breaks. This lesson shows the usual ways to install it on each operating system and how to check which version you are running.

Windows

Windows 10 and 11 include Windows PowerShell 5.1 out of the box (the blue icon). To get PowerShell 7, the easiest way is the Windows package manager winget, run from any terminal:

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

You can also install it from the Microsoft Store or download the .msi installer from the PowerShell GitHub releases page. After installing, open Windows Terminal and pick "PowerShell" (not "Windows PowerShell") from the drop-down, or type pwsh in any console.

macOS

With Homebrew:

text
brew install --cask powershell
pwsh

Linux

Microsoft publishes packages for the main distributions. On Ubuntu, after adding Microsoft's package repository:

text
sudo apt-get update
sudo apt-get install -y powershell
pwsh

Other options: sudo snap install powershell --classic, the .tar.gz archive (unpack and run ./pwsh), or the official Docker image mcr.microsoft.com/powershell. The examples in this course were verified with PowerShell 7.6 on Alpine Linux.

Check your version

Once pwsh starts, you see a prompt like PS /home/ada> (Linux/macOS) or PS C:\Users\Ada> (Windows). The current folder is shown after PS. Ask PowerShell about itself:

powershell · try it yourself
$PSVersionTable.PSVersion.ToString()
$PSVersionTable.PSEdition
$PSVersionTable.PSVersion -ge [version]'7.2'
7.6.1
Core
True

[version]'7.2' turns a string into a System.Version object, so the comparison works number by number (7.10 is newer than 7.9, which a plain string comparison would get wrong).

Which operating system am I on?

Scripts that must run everywhere often check the platform first. PowerShell 7 provides three ready-made Boolean variables:

powershell · try it yourself
"Windows: $IsWindows"
"Linux:   $IsLinux"
"macOS:   $IsMacOS"
[System.IO.Path]::DirectorySeparatorChar
Windows: False
Linux:   True
macOS:   False
/

The last line asks .NET for the folder separator: / on Linux and macOS, \ on Windows. PowerShell cmdlets accept both, so Join-Path and / in paths keep scripts portable.

Note: $IsWindows, $IsLinux and $IsMacOS do not exist in Windows PowerShell 5.1. There, they are simply $null, which counts as false.

Editors

You can write scripts in any text editor, but the recommended one is Visual Studio Code with the official PowerShell extension. It gives syntax highlighting, IntelliSense (completion of cmdlets and parameters), a debugger and the PSScriptAnalyzer linter. The old Windows PowerShell ISE still exists on Windows but only supports 5.1 and is no longer developed.

Your profile

Every time PowerShell starts, it runs your profile script if it exists. It's the place for your own aliases, functions and prompt tweaks. The path is stored in $PROFILE:

text
PS> $PROFILE
/home/ada/.config/powershell/Microsoft.PowerShell_profile.ps1     # Linux/macOS
C:\Users\Ada\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 # Windows
PS> code $PROFILE        # open it in VS Code (create it if needed)

The examples on this site are started with -NoProfile, so nothing from a profile changes their output.

Test yourself

Does installing PowerShell 7 on Windows remove Windows PowerShell 5.1?

  1. Yes, it upgrades it in place
  2. No, they are installed side by side
  3. Only on Windows 11
  4. Only if you use winget

Why compare versions with [version]'7.10' -gt [version]'7.9' instead of strings?

  1. Strings cannot be compared
  2. A version object compares each number part numerically
  3. It is faster
  4. Strings are case-sensitive

Which variable holds the path of your PowerShell profile script?

  1. $HOME
  2. $PSHOME
  3. $PROFILE
  4. $PSVersionTable