0
0
PowerShellscripting~10 mins

PowerShell versions (5.1 vs 7+) - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - PowerShell versions (5.1 vs 7+)
Start PowerShell
Check Version
Version 5.1
Windows-only
Legacy Cmdlets
End
PowerShell starts, checks its version, then follows different paths for version 5.1 (Windows-only) or 7+ (cross-platform with new features).
Execution Sample
PowerShell
Write-Host "PowerShell Version:" $PSVersionTable.PSVersion
if ($PSVersionTable.PSVersion.Major -ge 7) {
  Write-Host "You are using PowerShell 7 or newer."
} else {
  Write-Host "You are using PowerShell 5.1 or older."
}
This script prints the PowerShell version and tells if it's version 7+ or 5.1 or older.
Execution Table
StepActionEvaluationOutput
1Print PowerShell version$PSVersionTable.PSVersion = 7.2.1PowerShell Version: 7.2.1
2Check if Major version >= 77 >= 7 is TrueYou are using PowerShell 7 or newer.
3End script--
💡 Script ends after printing version info and message based on version check.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
$PSVersionTable.PSVersionN/A7.2.17.2.17.2.1
$PSVersionTable.PSVersion.MajorN/A777
Key Moments - 2 Insights
Why does the script check only the Major version number?
Because the Major version (like 5 or 7) tells us the big difference in features and compatibility, as shown in the execution_table step 2 where we compare Major version to 7.
Can PowerShell 7+ run on non-Windows systems?
Yes, PowerShell 7+ is cross-platform, unlike 5.1 which is Windows-only, as shown in the concept_flow branches.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table step 2, what is the Major version number used in the comparison?
A5
B7
C2
D1
💡 Hint
Check the 'Evaluation' column in step 2 of the execution_table.
At which step does the script decide which PowerShell version message to print?
AStep 1
BStep 3
CStep 2
DNo decision is made
💡 Hint
Look at the 'Action' and 'Output' columns in the execution_table.
If the Major version was 5, what would the output be at step 2?
A"You are using PowerShell 5.1 or older."
B"You are using PowerShell 7 or newer."
C"PowerShell Version: 5.1"
DNo output
💡 Hint
Refer to the if-else logic in the execution_sample code and the execution_table outputs.
Concept Snapshot
PowerShell versions differ mainly by Major version number.
Version 5.1 is Windows-only; 7+ is cross-platform.
Check $PSVersionTable.PSVersion.Major to detect version.
Use version check to run version-specific code.
PowerShell 7+ has new features and better performance.
Full Transcript
This lesson shows how PowerShell versions 5.1 and 7+ differ. The script prints the current PowerShell version and checks the Major version number. If the Major version is 7 or higher, it prints a message saying you are using PowerShell 7 or newer. Otherwise, it says you are using PowerShell 5.1 or older. Version 5.1 runs only on Windows, while 7+ works on Windows, Linux, and macOS. This helps you write scripts that behave correctly depending on the PowerShell version.