Installing PowerShell 7 and Setting Up Your Environment
Install PowerShell 7 on Windows, macOS or Linux next to Windows PowerShell 5.1, then set up a terminal, VS Code, a useful profile, execution policy and PSReadLine.
By The Dark DebuggerUpdated 23 min read
This article gets PowerShell 7 installed and turns a bare prompt into a comfortable working environment: terminal, editor, profile, execution policy and command-line editing. It assumes you've read the Introduction to PowerShell, so you know why PowerShell 7 and Windows PowerShell 5.1 are different products. Once you're set up, the next article, Cmdlets, Parameters, and the Help System, teaches you to find your way around.
Why bother installing PowerShell 7?
Every Windows machine already has Windows PowerShell 5.1, so it's fair to ask why you'd install
anything. Here's the kind of thing that happens if you don't. A colleague writes a deployment
helper in PowerShell 7 that uses the null-coalescing operator ?? to fall back to a default.
You run it in the built-in powershell.exe and get this:
$x = $null ?? 'default'At line:1 char:12
+ $x = $null ?? 'default'
+ ~~
Unexpected token '??' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedTokenWindows PowerShell 5.1 is frozen. It gets security fixes but no new language features, no new cmdlet parameters and no new .NET. PowerShell 7 gets all of those, runs the same scripts on Linux and macOS, and is what every other article in this path uses. A second, subtler reason shows up later in this article: 5.1 and 7 handle text encodings differently, and that alone breaks scripts.
Microsoft ships a new PowerShell 7 minor version roughly every year and keeps several of them patched. When I checked the GitHub releases on 9 November 2026, 7.6.9, 7.5.13 and 7.4.22 had all been published on 25 October 2026, and 7.7.0-rc.1 was available as a preview. Install the newest stable release unless something you depend on pins an older one.
Check what you already have
Open any PowerShell window and ask it for its version table. On my Windows 11 laptop, the
built-in Windows PowerShell reports PSVersion 5.1.26100.9711 and PSEdition Desktop (the
full output is in the introduction). Then check whether
PowerShell 7 is installed. This is Windows PowerShell 5.1 on a machine where it isn't:
Get-Command pwshGet-Command : The term 'pwsh' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Command pwsh
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (pwsh:String) [Get-Command], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommandNo pwsh, so let's install it.
Installing on Windows
There are three good ways. I didn't run the install commands on my Windows host, because this
article's rule for the Windows machine is read-only commands only, but I did run the read-only
winget show below.
winget (recommended)
winget is the package manager built into current Windows 10 and 11. First see what it would
install:
winget show --id Microsoft.PowerShell --source wingetFound PowerShell [Microsoft.PowerShell]
Version: 7.6.9.0
Publisher: Microsoft Corporation
Publisher Url: https://github.com/PowerShell/PowerShell/
[…]
Installer:
Installer Type: msix
Installer Url: https://github.com/PowerShell/PowerShell/releases/download/v7.6.9/PowerShell-7.6.9.msixbundle
Installer SHA256: da75c8aa23edda52e888fb586a46b923ab37a7c243719c2e8914b00130c5917a
Release Date: 2026-10-25
Offline Distribution Supported: trueThen install, and later upgrade, with (not run here):
winget install --id Microsoft.PowerShell --source winget
winget upgrade --id Microsoft.PowerShell --source wingetThe preview channel is a separate package, Microsoft.PowerShell.Preview, and installs next to
the stable one.
The MSI package
For servers, golden images and anything managed by Configuration Manager or Intune, the MSI from the GitHub releases page is the classic choice. It can be installed silently. Not run here:
msiexec.exe /package PowerShell-7.6.9-win-x64.msi /quiet ADD_PATH=1 ENABLE_PSREMOTING=1 USE_MU=1 ENABLE_MU=1ADD_PATH=1 puts pwsh.exe on the PATH, ENABLE_PSREMOTING=1 sets up remoting endpoints, and
the two MU properties let Microsoft Update patch PowerShell along with Windows. The full list
of properties is in Microsoft's
Windows install documentation.
The Microsoft Store
The Store package installs per user and updates itself, which is convenient on a personal
laptop. It runs in an app container, though, and Microsoft documents some limitations around
writing to locations such as $PSHOME. For admin work and servers I recommend winget or the
MSI.
What you end up with
After installing, Windows has both PowerShells side by side. Nothing about 5.1 changes:
| Windows PowerShell 5.1 | PowerShell 7 | |
|---|---|---|
| Executable | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe | C:\Program Files\PowerShell\7\pwsh.exe (MSI/winget default) |
| Your profile folder | Documents\WindowsPowerShell | Documents\PowerShell |
| Execution policy stored in | the registry | powershell.config.json files |
| Start menu name | Windows PowerShell | PowerShell 7 |
The separate profile folders matter: customising one doesn't customise the other. More on that in the profiles section below.
Installing on macOS
On macOS, use Homebrew. When I checked Homebrew's package index on 9 November 2026, stable
PowerShell was published as the powershell formula at version 7.6.9 and the preview as the
powershell@preview cask. I don't have a Mac in the lab, so these commands were not run:
brew install powershell
brew upgrade powershell
pwshIf an older guide tells you to use brew install --cask powershell, check brew info powershell
first; package names in Homebrew change over time.
Installing on Linux
From Microsoft's package repository
On Ubuntu and Debian, the most maintainable install is Microsoft's apt repository, because
apt upgrade then keeps PowerShell patched. This is Microsoft's documented recipe for Ubuntu;
my lab user has no sudo, so I didn't run it, but I did confirm that the repository for Ubuntu
24.04 lists powershell package versions up to 7.6.9:
sudo apt-get update
sudo apt-get install -y wget apt-transport-https software-properties-common
source /etc/os-release
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y powershellFor RHEL, Fedora, SUSE and others, follow the matching page in Microsoft's Linux install documentation.
From the tarball, without root (what I did)
The tarball works on any x64 Linux with glibc and needs no root access. It's also how you run two PowerShell versions side by side. These are the commands I ran on Ubuntu 24.04, installing into my home directory. Download the release and its checksum file:
cd ~/Downloads
curl -sSLO https://github.com/PowerShell/PowerShell/releases/download/v7.6.9/powershell-7.6.9-linux-x64.tar.gz
curl -sSLO https://github.com/PowerShell/PowerShell/releases/download/v7.6.9/hashes.sha256
ls -ltotal 71688
-rw-r--r-- 1 sid sid 7358 Nov 9 21:30 hashes.sha256
-rw-r--r-- 1 sid sid 73399520 Nov 9 21:30 powershell-7.6.9-linux-x64.tar.gzAlways verify a download before you unpack and run it. This is where I hit the surprise of the day. The obvious command fails:
grep ' powershell-7.6.9-linux-x64.tar.gz$' hashes.sha256 | sha256sum -c -sha256sum: 'standard input': no properly formatted checksum lines foundThe checksum file is generated on Windows, and it shows:
file hashes.sha256hashes.sha256: Unicode text, UTF-16, little-endian text, with CRLF line terminatorsgrep and sha256sum expect UTF-8 (or ASCII) with Unix line endings. Convert it first, and
the check passes:
iconv -f UTF-16 -t UTF-8 hashes.sha256 | tr -d '\r' | grep 'linux-x64.tar.gz'1da6d6d6035d651f20e70ddee7c4c15ac6ab8b9fb40ee92240d91263f28a884b *powershell-7.6.9-linux-x64.tar.gziconv -f UTF-16 -t UTF-8 hashes.sha256 | tr -d '\r' | grep ' \*powershell-7.6.9-linux-x64.tar.gz$' | sha256sum -c -powershell-7.6.9-linux-x64.tar.gz: OKNow unpack it into a versioned folder and link the launcher onto your PATH:
mkdir -p ~/.local/opt/powershell/7.6.9 ~/.local/bin
tar -xzf powershell-7.6.9-linux-x64.tar.gz -C ~/.local/opt/powershell/7.6.9
chmod +x ~/.local/opt/powershell/7.6.9/pwsh
ln -sfn ~/.local/opt/powershell/7.6.9/pwsh ~/.local/bin/pwshIn my test the pwsh launcher already had its execute bit after unpacking, so the chmod is
just insurance. The unpacked install took 172 MB. Because each version lives in its own folder,
upgrading later means unpacking 7.6.10 next to it and re-pointing the symlink; rolling back is
re-pointing it again.
On Ubuntu, ~/.local/bin is added to your PATH at login only if it existed when you logged in.
In a shell where it isn't on the PATH yet, you get:
pwshbash: pwsh: command not foundAdd it for the current shell (and log out and back in to make it permanent), then check:
export PATH="$HOME/.local/bin:$PATH"
pwsh --versionPowerShell 7.6.9If you have root and want it system-wide, Microsoft's equivalent uses
/opt/microsoft/powershell/7 and a symlink in /usr/bin, with sudo in front of each step.
Confirm the install
Start pwsh. $PSVersionTable (shown in full in the
introduction) tells you what you're running, and
$PSHOME tells you where it's installed:
$PSVersionTable.PSEdition
$PSHOMECore
/home/sid/.local/opt/powershell/7.6.9PSEdition is Core for PowerShell 7 and Desktop for Windows PowerShell 5.1. Scripts that
must refuse to run on an old version can test the version directly, because PSVersion is a
real [version] object that compares correctly:
$PSVersionTable.PSVersion -ge [version]'7.4'TrueWindows Terminal
On Windows, use Windows Terminal rather than
the old console window. It's included with Windows 11 and adds tabs, panes, proper Unicode
rendering and per-shell profiles. After you install PowerShell 7, Windows Terminal detects it
and adds a "PowerShell" profile next to "Windows PowerShell". Make it the default in
Settings > Startup > Default profile, so new tabs open pwsh. On macOS and Linux, any modern
terminal works; just run pwsh.
VS Code and the PowerShell extension
For writing scripts, use VS Code with Microsoft's PowerShell extension (ID
ms-vscode.powershell). It gives you IntelliSense for cmdlets and parameters, inline
warnings from PSScriptAnalyzer, a debugger with breakpoints, and an integrated PowerShell
console. Install it from the Extensions view, or from a terminal (not run here):
code --install-extension ms-vscode.powershellTwo settings matter more than the rest:
- Which PowerShell the extension uses. Click the PowerShell version in the status bar and pick PowerShell 7. If you also need to test against 5.1, you can switch per session.
- File encoding. VS Code saves files as UTF-8 without a byte-order mark (BOM). PowerShell 7 reads that correctly. Windows PowerShell 5.1 does not: without a BOM it assumes your Windows "ANSI" code page.
That second point bit me while preparing this article. I saved this one-line script as UTF-8 without a BOM:
Write-Output 'Café opens at 07:00 — closed Sundays'Running it with Windows PowerShell 5.1 printed:
Café opens at 07:00 — closed SundaysThe UTF-8 bytes for é and — were decoded as Windows-1252 characters. If a script has to run
under 5.1 and contains anything outside plain ASCII, save it as "UTF-8 with BOM" (VS Code's
status bar lets you change the encoding per file).
Profiles: your startup script
A profile is a script PowerShell runs every time it starts, the equivalent of .bashrc. There
are four of them. $PROFILE on its own is one path, but it carries all four as properties:
$PROFILE | Select-Object AllUsersAllHosts, AllUsersCurrentHost, CurrentUserAllHosts, CurrentUserCurrentHost | Format-List
AllUsersAllHosts : /home/sid/.local/opt/powershell/7.6.9/profile.ps1
AllUsersCurrentHost : /home/sid/.local/opt/powershell/7.6.9/Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : /home/sid/.config/powershell/profile.ps1
CurrentUserCurrentHost : /home/sid/.config/powershell/Microsoft.PowerShell_profile.ps1
The "AllUsers" profiles live in $PSHOME, wherever PowerShell itself is installed (here, my
lab's install folder). The "CurrentUser" ones live in your home directory.
"AllHosts" profiles run in every host: the console, VS Code's integrated console, and others.
"CurrentHost" profiles run only in the host you're in. Plain $PROFILE means
CurrentUserCurrentHost.
On Windows, the CurrentUser profiles for PowerShell 7 are under Documents\PowerShell\, and
for Windows PowerShell 5.1 under Documents\WindowsPowerShell\. If your Documents folder is
redirected to OneDrive, those paths are inside OneDrive.
My recommendation: put personal settings in CurrentUserAllHosts (profile.ps1), so the
console and VS Code behave the same. A fresh install has none of these files:
$PROFILE.PSObject.Properties | Where-Object MemberType -eq 'NoteProperty' | ForEach-Object { '{0,-24} {1}' -f $_.Name, (Test-Path $_.Value) }AllUsersAllHosts False
AllUsersCurrentHost False
CurrentUserAllHosts False
CurrentUserCurrentHost FalseA useful starter profile
Create the file with
New-Item -ItemType File -Path $PROFILE.CurrentUserAllHosts -Force and open it in your editor.
Here is a small profile that I tested; every line earns its place, and it works in both 5.1 and
7:
# profile.ps1 - CurrentUserAllHosts profile.
# Runs at the start of every session for this user. Keep it fast and quiet.
# PSReadLine: only in an interactive console, and only with options this version has.
if ($Host.Name -eq 'ConsoleHost' -and (Get-Command Set-PSReadLineOption -ErrorAction Ignore)) {
$psrl = Get-Command Set-PSReadLineOption
if ($psrl.Parameters.ContainsKey('PredictionSource')) {
Set-PSReadLineOption -PredictionSource History
}
Set-PSReadLineOption -HistoryNoDuplicates
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
}
# Windows PowerShell 5.1 writes UTF-16 with Out-File and >. Match PowerShell 7.
if ($PSVersionTable.PSEdition -eq 'Desktop') {
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
}
# Short prompt: major version and the current folder name.
function prompt {
$folder = Split-Path -Path $PWD.Path -Leaf
"PS$($PSVersionTable.PSVersion.Major) $folder> "
}
# Make a directory (and parents) and move into it.
function mkcd {
param([Parameter(Mandatory)][string]$Path)
New-Item -ItemType Directory -Path $Path -Force | Out-Null
Set-Location -Path $Path
}What each part does:
- PSReadLine settings. Up and Down arrows search history for lines starting with what you've
already typed (type
gitthen press Up). Tab shows a menu of completions. History-based suggestions are enabled only if the installed PSReadLine supports them, because Windows PowerShell 5.1 ships PSReadLine 2.0.0, which has no-PredictionSourceparameter at all. Calling it unguarded would put an error on screen every time 5.1 starts. - Encoding default. Makes 5.1's
Out-Fileand>write UTF-8 instead of UTF-16. It is skipped in PowerShell 7, which already defaults to UTF-8. prompt. PowerShell calls a function namedpromptto draw the prompt. This one showsPS7 logs>instead of the full path, and the version number tells you at a glance whether you're in 5.1 or 7.mkcd. Create a folder (and any missing parents) and step into it, in one command.
With the file saved, a new session picks it up. Checked from Bash, with and without
-NoProfile:
pwsh -Command 'Test-Path $PROFILE.CurrentUserAllHosts; Get-Command mkcd | Select-Object CommandType, Name'True
CommandType Name
----------- ----
Function mkcd
pwsh -NoProfile -Command 'Get-Command mkcd'Get-Command: The term 'mkcd' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.That second result is a feature: scheduled tasks and CI jobs should run with -NoProfile, so
they don't depend on whatever a person put in their profile. Profiles also cost startup time on
every launch, so keep an eye on it:
pwsh -Command '(Measure-Command { . $PROFILE.CurrentUserAllHosts }).TotalMilliseconds'23.2432About 23 ms. If yours creeps past a second, look for module imports or network calls you can
remove or load lazily. And here is the prompt in an interactive session, using mkcd:
PS7 demo> mkcd reports/2026-11
PS7 2026-11> Get-Location
Path
----
/home/sid/demo/reports/2026-11
PS7 2026-11>Execution policy, honestly
On Windows, the first script you run in Windows PowerShell 5.1 may fail like this (I triggered
it by running a one-line script with the policy set to Restricted for that process):
.\deploy.ps1 : File C:\Users\[…]\deploy.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\deploy.ps1
+ ~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess(I trimmed the folder path, which included my Windows user name.)
What execution policy is: a Windows setting that controls whether PowerShell will load
script files (.ps1, .psm1) and configuration files. The common values:
| Policy | Effect |
|---|---|
Restricted | No scripts at all; interactive commands only. The default on Windows client editions. |
RemoteSigned | Local scripts run. Scripts marked as downloaded from the internet must be signed. The default on Windows Server. |
AllSigned | Every script must be signed by a trusted publisher. |
Bypass | Nothing is blocked and nothing warns. Used by automation that manages its own trust. |
Unrestricted | Everything runs; downloaded scripts trigger a warning prompt. |
Policies are set per scope, and the most specific scope wins: Group Policy (MachinePolicy,
UserPolicy) beats Process, which beats CurrentUser, which beats LocalMachine. This is
Windows PowerShell 5.1 on my test laptop, where the CurrentUser scope was already set to
RemoteSigned:
Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine UndefinedWhat it is not: a security boundary. Microsoft's own documentation says so. Anyone who can
run powershell.exe can override it for one process, which is exactly how I produced the error
above, and the reverse works just as easily:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\deploy.ps1deployingThink of it as a seatbelt against accidentally double-clicking or running an untrusted script, not as protection against an attacker. Real protection comes from application control (AppLocker or Windows Defender Application Control), which also puts PowerShell into Constrained Language Mode.
What I recommend on a workstation: RemoteSigned for your own user. Not run here, since it
changes the host:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser"Downloaded from the internet" means the file carries a Mark of the Web, which browsers and mail
clients add. If you've reviewed a downloaded script and trust it, Unblock-File -Path .\script.ps1
removes the mark. PowerShell 7 keeps its own execution policy settings, separate from 5.1's,
so check each with Get-ExecutionPolicy -List in each shell.
On Linux and macOS there is no execution policy. It always reports Unrestricted and can't
be changed:
Get-ExecutionPolicy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserUnrestricted
Set-ExecutionPolicy: Operation is not supported on this platform.There, normal file permissions decide what runs, as with any other script.
PSReadLine: command-line editing
PSReadLine is the module that gives the interactive prompt syntax colouring, history search, completion menus and predictions. PowerShell 7.6 ships version 2.4.5; Windows PowerShell 5.1 ships 2.0.0.
Get-Module -ListAvailable -Name PSReadLine | Select-Object Name, Version
Name Version
---- -------
PSReadLine 2.4.5
You don't need to memorise its options; ask it. These are the defaults before my profile changes anything:
Get-PSReadLineOption | Select-Object EditMode, PredictionSource, PredictionViewStyle, HistorySavePath
EditMode PredictionSource PredictionViewStyle HistorySavePath
-------- ---------------- ------------------- ---------------
Emacs HistoryAndPlugin InlineView /home/sid/.local/share/powershell/PSReadLine/Console…
The edit mode is Emacs on Linux and macOS and Windows on Windows, so Ctrl+A, Ctrl+E and
friends behave as in Bash on Linux. HistorySavePath is the file holding your command history
across sessions; it's plain text, which is worth knowing before you paste a password into a
command line. Three key bindings are worth learning first:
Get-PSReadLineKeyHandler -Chord Ctrl+r, F2, Tab | Select-Object Key, Function
Key Function
--- --------
Ctrl+r ReverseSearchHistory
Tab Complete
F2 SwitchPredictionView
Ctrl+R works like Bash's reverse history search. Tab completes commands, parameters and
paths (press it twice to see all candidates; my profile switches it to a menu). F2 switches
predictions between a single grey inline suggestion and a list you can arrow through. Run
Get-PSReadLineKeyHandler with no arguments for the full list. In Windows edit mode,
Ctrl+Space also opens a completion menu.
Where you'll use this
The same setup decisions come up whenever you prepare a machine: a new laptop, a build agent, a jump box for an operations team. Rather than checking by hand, put the checks in a script so CI or a provisioning tool can run it and fail loudly. A complete example:
# Test-ShellSetup.ps1 - check that a workstation or build agent is ready for PowerShell work.
# Exit code 0 = all checks passed, 1 = at least one failed (CI systems read this).
$readline = Get-Module -ListAvailable -Name PSReadLine |
Sort-Object Version -Descending | Select-Object -First 1
$git = Get-Command git -ErrorAction Ignore
$checks = @(
[pscustomobject]@{
Check = 'PowerShell 7.4 or newer'
Passed = $PSVersionTable.PSVersion -ge [version]'7.4'
Detail = "$($PSVersionTable.PSVersion) $($PSVersionTable.PSEdition)"
}
[pscustomobject]@{
Check = 'Profile exists'
Passed = Test-Path -Path $PROFILE.CurrentUserAllHosts
Detail = Split-Path -Path $PROFILE.CurrentUserAllHosts -Leaf
}
[pscustomobject]@{
Check = 'PSReadLine 2.2 or newer'
Passed = $readline.Version -ge [version]'2.2'
Detail = "$($readline.Version)"
}
[pscustomobject]@{
Check = 'git available'
Passed = $null -ne $git
Detail = "$($git.Source)"
}
[pscustomobject]@{
Check = 'Scripts allowed to run'
Passed = (Get-ExecutionPolicy) -notin 'Restricted', 'AllSigned'
Detail = "$(Get-ExecutionPolicy)"
}
)
$checks | Format-Table -AutoSize
if ($checks.Passed -contains $false) { exit 1 }On my Linux lab user, before creating a profile:
./Test-ShellSetup.ps1
$LASTEXITCODE
Check Passed Detail
----- ------ ------
PowerShell 7.4 or newer True 7.6.9 Core
Profile exists False profile.ps1
PSReadLine 2.2 or newer True 2.4.5
git available True /usr/bin/git
Scripts allowed to run True Unrestricted
1One failed check, exit code 1. After installing the profile from this article, the same script
reported True for every row and exited normally. The building blocks
([pscustomobject], arrays, -notin, exit codes) are covered properly in
Arrays, Hashtables, and Custom Objects,
Operators and
Scripts, Scope, and Modules.
Common mistakes
Editing the profile of the other PowerShell
You add a function to your profile, open a new window, and it isn't there. Nine times out of
ten you edited Documents\WindowsPowerShell\... (5.1) and opened PowerShell 7, or the other way
round. Don't guess the path: in the shell you want to customise, run $PROFILE (or
$PROFILE.CurrentUserAllHosts) and edit exactly that file, for example with
code $PROFILE.CurrentUserAllHosts. The same applies to execution policy and installed modules;
5.1 and 7 keep separate settings for all three.
Verifying the Linux tarball with the checksum file as-is
As shown above, hashes.sha256 is UTF-16 with CRLF line endings, so sha256sum -c reports
no properly formatted checksum lines found. That message doesn't mean the download is corrupt;
it means sha256sum couldn't read the checksum file. Convert it with iconv and tr -d '\r'
first. Don't skip the check because the first attempt failed.
"pwsh: command not found" after a tarball install
The files are there but the shell can't find them, because ~/.local/bin isn't on the PATH of
the shell you're in. Run export PATH="$HOME/.local/bin:$PATH" for now, and log out and back in
(or add that line to ~/.profile) to make it stick.
Writing files from Windows PowerShell 5.1 and reading them elsewhere
In 5.1, Out-File and the > operator write UTF-16LE with a byte-order mark. This is 5.1
writing web01 OK and the first eight bytes of the result:
'web01 OK' | Out-File status.txt
Get-Content .\status.txt -Encoding Byte -TotalCount 8255
254
119
0
101
0
98
0255 254 is the UTF-16LE byte-order mark, and every ASCII letter is followed by a zero byte.
Linux tools, many parsers and Git diffs choke on that. PowerShell 7 writes the same text as
plain UTF-8 without a BOM:
'web01 OK' | Out-File status.txt
Format-Hex -Path status.txt
Label: /home/sid/demo/status.txt
Offset Bytes Ascii
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
------ ----------------------------------------------- -----
0000000000000000 77 65 62 30 31 20 4F 4B 0A web01 OK�
The fix in 5.1 is -Encoding utf8 on each command, or the $PSDefaultParameterValues line in
the starter profile. (One more version difference hiding in that example: -Encoding Byte
doesn't exist in PowerShell 7, which rejects it with 'Byte' is not a supported encoding name.
Use -AsByteStream there.)
Summary
- Install PowerShell 7 alongside Windows PowerShell 5.1; it never replaces it. Use winget or the
MSI on Windows, the
powershellHomebrew formula on macOS, Microsoft's package repository or the tarball on Linux. - Verify Linux tarballs with
hashes.sha256, converting that file from UTF-16 and CRLF first. $PSVersionTable.PSVersionis a[version]you can compare;PSEditionisCorefor 7 andDesktopfor 5.1.$PROFILEhas four variants. Put your settings in$PROFILE.CurrentUserAllHosts, keep the profile fast, and run automation with-NoProfile.- 5.1 and 7 keep separate profiles, module folders and execution policy settings.
- Execution policy is a Windows safety net against accidental script runs, not a security
boundary.
RemoteSignedforCurrentUseris a sensible workstation setting; on Linux and macOS the policy doesn't apply. - PSReadLine gives you history search (
Ctrl+R), completion (Tab) and predictions (F2to switch views). Guard newer options in profiles that also run under 5.1. - 5.1 writes UTF-16 by default and misreads BOM-less UTF-8 scripts; save cross-version scripts as UTF-8 with BOM if they contain non-ASCII characters.
Exercises
Write one line that prints True if the current PowerShell is 7.4 or newer and False
otherwise. Then explain why comparing $PSVersionTable.PSVersion.ToString() to '7.4' as text
would be a bad idea.
Show Solution
$PSVersionTable.PSVersion -ge [version]'7.4'TruePSVersion is a System.Version object, and casting '7.4' to [version] makes the
comparison numeric, part by part. As strings, '7.10.0' -ge '7.4' would be False, because
text compares character by character and 1 sorts before 4.
Print each of the four profile names with True or False depending on whether that file
exists on your machine.
Hint
$PROFILE is a string with four extra NoteProperty members. $PROFILE.PSObject.Properties
lists them, each with a Name and a Value.
Show Solution
$PROFILE.PSObject.Properties | Where-Object MemberType -eq 'NoteProperty' | ForEach-Object { '{0,-24} {1}' -f $_.Name, (Test-Path $_.Value) }After installing the starter profile into CurrentUserAllHosts, I got:
AllUsersAllHosts False
AllUsersCurrentHost False
CurrentUserAllHosts True
CurrentUserCurrentHost FalseThe -f format operator used here is explained in
String Formatting, Split, Join, Replace, and Other Operators.
Add a function called mkcd to your CurrentUserAllHosts profile (use the starter profile).
From a Bash or cmd prompt, show that pwsh can see the function normally but not when
started with -NoProfile.
Show Solution
pwsh -Command 'Get-Command mkcd | Select-Object CommandType, Name'
pwsh -NoProfile -Command 'Get-Command mkcd'
CommandType Name
----------- ----
Function mkcd
Get-Command: The term 'mkcd' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.Scheduled tasks, CI jobs and anything else unattended should use -NoProfile, so a change to
someone's personal profile can never break them.
Tested with: PowerShell 7.6.9 on Ubuntu 24.04 (WSL2), and Windows PowerShell
5.1.26100.9711 on Windows 11, November 2026. The Linux tarball install was performed for real
(download, checksum, unpack, symlink, PATH), into a throwaway home directory so it couldn't
disturb the rest of my lab; the profile was tested the same way, including an interactive
session for the prompt. The winget, MSI, Microsoft Store, Homebrew, apt, VS Code extension and
Set-ExecutionPolicy commands were not run: they install software or change settings on the
host, or need a Mac or root. I did check that the winget package, the apt repository and the
Homebrew formula all offered 7.6.9 on the day of testing. Windows outputs (the ?? and
Get-Command pwsh errors, winget show, execution policy, UTF-16 bytes and the BOM mojibake)
came from read-only or scratch-folder commands in Windows PowerShell 5.1. Paths from the test machine's scratch directories are shown shortened to /home/sid/….
Written by The Dark Debugger
Engineer documenting the things that took me too long to learn, so they take you less time. Every PowerShell tutorial here is tested end to end before publishing.