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:
winget search Microsoft.PowerShell
winget install --id Microsoft.PowerShell --source wingetYou 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:
brew install --cask powershell
pwshLinux
Microsoft publishes packages for the main distributions. On Ubuntu, after adding Microsoft's package repository:
sudo apt-get update
sudo apt-get install -y powershell
pwshOther 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:
$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:
"Windows: $IsWindows"
"Linux: $IsLinux"
"macOS: $IsMacOS"
[System.IO.Path]::DirectorySeparatorCharWindows: 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,$IsLinuxand$IsMacOSdo 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:
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?
- Yes, it upgrades it in place
- No, they are installed side by side
- Only on Windows 11
- Only if you use winget
Why compare versions with [version]'7.10' -gt [version]'7.9' instead of strings?
- Strings cannot be compared
- A version object compares each number part numerically
- It is faster
- Strings are case-sensitive
Which variable holds the path of your PowerShell profile script?
- $HOME
- $PSHOME
- $PROFILE
- $PSVersionTable