PowerShell 7

Table of Contents
-
- 4.1. Installation
- 4.2. Running PowerShell 7
Introduction
PowerShell 7 is a cross-platform shell and scripting language developed by Microsoft. Unlike the traditional Windows PowerShell (5.1), it is based on .NET Core (currently 1 .NET 8/9) and runs on Windows, Linux, and macOS.
PowerShell 7 has many improvements compared to 5.1.
- Cross-platform support Works on operating systems other than Windows
- Improved performance Faster processing of large data volumes
- New language features
- Supports parallel processing with
ForEach-Object -Parallel
- Ternary operator: Supports the
$condition ? $true : $false
syntax - Null conditional operator:
?.
, Null coalescing operator:??
added
- Supports parallel processing with
With support for the ternary operator and null conditional operator, which are frequently used in C#, it's now easier to write more compact scripts. Since it also supports .NET 8, I decided to install it on my machine, albeit a bit late.
Installing PowerShell 7
To install PowerShell 7, use winget
2.
winget install --id Microsoft.PowerShell --source winget
Installation is now complete. Let's start PowerShell and check the version.
PS C:\hoge> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 26100 6584
Huh? That's strange (;^_^A Actually, PowerShell 7 is installed as a separate application from Windows PowerShell 5.1. This means that even after installation, the PowerShell (powershell.exe) that was originally there remains 5.1 and does not change. PowerShell 7 is installed under the name pwsh.exe and is usually located at the following path:
C:\Program Files\PowerShell\7\pwsh.exe
The difference in installation paths between PowerShell 5.1 and 7.x is as follows:
Version | Executable file name | Default location |
---|---|---|
PowerShell 5.1 | powershell.exe | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe |
PowerShell 7.x | pwsh.exe | C:\Program Files\PowerShell\7\pwsh.exe |
Below, we will explain how to run PowerShell 7.
Launching PowerShell 7
Launching PowerShell 7 Directly
- Search for "PowerShell 7" or "pwsh" in the Start menu and run it
- Press
Win
+R
→ typepwsh
and run it - Type
pwsh
in the Command Prompt or PowerShell prompt and run it
Changing Windows Terminal Settings
By changing the Default profile
in Terminal, you can configure it to automatically launch PowerShell 7 when Terminal starts.
1Launch Terminal and go to ▼
> Settings
at the top of the window (Figure 1.)
2Select Default profile
(Figure 2.) > PowerShell
(Figure 3.)
Figure 2. Startup
Figure 3. Default Profile Selection
Windows PowerShell
refers to PowerShell 5.1, andPowerShell
refers to PowerShell 7.
3Click the Save
button to save the settings (Figure 4.).
Now, PowerShell 7 will launch automatically the next time you open Terminal.
Changing the PowerShell executed in Visual Studio Code to 7
To change the PowerShell executed in Visual Studio Code's terminal to PowerShell 7, follow these steps:
- Install the PowerShell extension (@microsoft.com)
- Open the user settings file with
Ctrl + Shift + P
>Preferences: Open User Settings (JSON)
- Add the following to the end of the settings file and save
"terminal.integrated.profiles.windows": {
"PowerShell 7": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
}
},
"terminal.integrated.defaultProfile.windows": "PowerShell 7"
- Launch Terminal and verify
If
pwsh
is displayed in the upper right corner when Terminal starts, the changes have been applied. Just to be sure, let's check the version with$PSVersionTable.PSVersion
. Figure 5.
That completes the settings for Visual Studio Code.
Changing the PowerShell executed in Visual Studio 2022 to 7
To change the PowerShell version executed in Visual Studio 2022 to 7, modify the settings from Options. Tools > Options > Environment > Terminal > Developer PowerShell Change "Shell location" from
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
to
C:\Program Files\PowerShell\7\pwsh.exe
(Figure 6.).
Using PowerShell 7 on Linux (WSL)
PowerShell 7 supports cross-platform. Let's try running PowerShell 7 in a WSL (Ubuntu Linux) environment.
Installation
1Preparation
As a preparatory step, let's check the WSL (Ubuntu) version.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
My Ubuntu was 22.04
.
2Add Microsoft's repository
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
Please change the ubuntu/22.04
part to match your OS / version.
3Install PowerShell 7
sudo apt-get install -y powershell
Running PowerShell 7
Similar to the Windows version, the executable file name is pwsh
.
pwsh
$ pwsh
PowerShell 7.5.3
PS /mnt/c/hoge>
PowerShell has started. Although the version number is displayed on startup, let's re-check the version with a cmdlet.
PS /mnt/c/hoge> $PSVersionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 5 3
It's displayed. Commandlet autocompletion also works, similar to the Windows version.
Summary
We have introduced PowerShell 7, from its overview to installation methods, and procedures for changing PowerShell in Windows Terminal and Visual Studio Code to version 7. Since it can also be used on Linux, unifying shell scripts with PowerShell could be an option.
References
What is PowerShell - PowerShell | Microsoft Learn
Footnotes
-
As of 2025-09-11.↩
-
Install and manage applications with the winget tool | Microsoft Learn↩