0
0
PowerShellscripting~5 mins

PowerShell versions (5.1 vs 7+)

Choose your learning style9 modes available
Introduction
PowerShell versions 5.1 and 7+ are different tools to run commands and scripts on Windows and other systems. Knowing the difference helps you pick the right one for your tasks.
You want to run scripts on Windows with full Windows system support.
You need to run PowerShell on Mac or Linux computers.
You want to use the latest features and faster performance.
You have old scripts that only work on Windows PowerShell 5.1.
You want to use cross-platform tools and modules.
Syntax
PowerShell
To check your PowerShell version, run:
$PSVersionTable.PSVersion
PowerShell 5.1 is the last Windows-only version installed by default on Windows 10 and earlier.
PowerShell 7+ is a newer, cross-platform version that works on Windows, Mac, and Linux.
Examples
Shows the current PowerShell version you are using.
PowerShell
$PSVersionTable.PSVersion
Command to start PowerShell 7+ if installed alongside Windows PowerShell 5.1.
PowerShell
pwsh
Another way to see the PowerShell version.
PowerShell
Get-Host | Select-Object Version
Sample Program
This script prints your PowerShell version and tells you if you can use a new feature available only in PowerShell 7 or newer.
PowerShell
# Check PowerShell version
Write-Output "Your PowerShell version is: $($PSVersionTable.PSVersion)"

# Example: Use a feature only in PowerShell 7+
if ($PSVersionTable.PSVersion.Major -ge 7) {
    Write-Output "You can use the new 'ForEach-Object -Parallel' feature!"
} else {
    Write-Output "You are using Windows PowerShell 5.1 or older."
}
OutputSuccess
Important Notes
PowerShell 5.1 is built into Windows but does not run on Mac or Linux.
PowerShell 7+ is installed separately and can run on many operating systems.
Some older scripts may need changes to work in PowerShell 7+.
Summary
PowerShell 5.1 is Windows-only and comes pre-installed on many Windows PCs.
PowerShell 7+ is newer, faster, and works on Windows, Mac, and Linux.
Check your version with $PSVersionTable.PSVersion to know what features you can use.