What is the main difference between PowerShell 5.1 and PowerShell 7+?
PowerShell 5.1 is Windows-only and built on .NET Framework, while PowerShell 7+ is cross-platform and built on .NET Core (now .NET 5+), allowing it to run on Windows, Linux, and macOS.
Click to reveal answer
beginner
Which PowerShell version supports running on Linux and macOS?
PowerShell 7+ supports running on Linux and macOS, unlike PowerShell 5.1 which only runs on Windows.
Click to reveal answer
intermediate
How does PowerShell 7+ improve performance compared to 5.1?
PowerShell 7+ uses the newer .NET Core runtime (now .NET 5+) which is faster and more efficient than the .NET Framework used in 5.1, leading to better performance.
Click to reveal answer
intermediate
Can PowerShell 7+ run existing scripts made for PowerShell 5.1 without changes?
Most scripts run fine, but some Windows-specific modules or commands may need adjustments because PowerShell 7+ is cross-platform and some Windows-only features are not available.
Click to reveal answer
beginner
Why might someone still use PowerShell 5.1 instead of 7+?
Because PowerShell 5.1 is built into Windows and supports some legacy Windows modules that are not yet fully compatible with PowerShell 7+.
2. Which of the following is the correct PowerShell command to check your PowerShell version?
easy
A. $PSVersionTable.PSVersion
B. Get-PSVersion
C. Check-PSVersion
D. Show-Version
Solution
Step 1: Recall the built-in variable for version info
$PSVersionTable is a built-in variable that holds version details.
Step 2: Access the PSVersion property
Using $PSVersionTable.PSVersion returns the current PowerShell version object.
Final Answer:
$PSVersionTable.PSVersion -> Option A
Quick Check:
Check version = $PSVersionTable.PSVersion [OK]
Hint: Use $PSVersionTable.PSVersion to see your PowerShell version [OK]
Common Mistakes:
Using non-existent commands like Get-PSVersion
Confusing variable names
Trying commands that don't exist in PowerShell
3. What will be the output of this command in PowerShell 7+?
$PSVersionTable.PSVersion.Major
medium
A. 5
B. Error: Property not found
C. 1
D. 7
Solution
Step 1: Understand the command
$PSVersionTable.PSVersion returns a version object; .Major accesses the major version number.
Step 2: Identify the major version in PowerShell 7+
PowerShell 7+ means the major version is 7, so the output is 7.
Final Answer:
7 -> Option D
Quick Check:
Major version in PS 7+ = 7 [OK]
Hint: Major version number is the first digit in $PSVersionTable.PSVersion [OK]
Common Mistakes:
Assuming major version is 5 for PowerShell 7+
Expecting full version string instead of major number
Thinking .Major property does not exist
4. You run this script in PowerShell 5.1:
if ($PSVersionTable.PSVersion.Major -ge 7) { Write-Output "New version" } else { Write-Output "Old version" }
But it always outputs "Old version" even on PowerShell 7+. What is the likely problem?
medium
A. The script is running in PowerShell 5.1, not 7+.
B. The comparison operator -ge is invalid in PowerShell 5.1.
C. $PSVersionTable.PSVersion does not exist in PowerShell 5.1.
D. Write-Output cannot print strings in PowerShell 7+.
Solution
Step 1: Analyze the condition logic
The script checks if major version is 7 or greater to print "New version".
Step 2: Understand why it outputs "Old version"
If it always prints "Old version", the major version is less than 7, meaning the script runs in PowerShell 5.1 or older.
Final Answer:
The script is running in PowerShell 5.1, not 7+. -> Option A
Quick Check:
Output "Old version" means PS version < 7 [OK]
Hint: If condition fails, check which PowerShell version runs the script [OK]
Common Mistakes:
Thinking -ge operator is invalid in 5.1
Assuming $PSVersionTable.PSVersion is missing in 5.1
Believing Write-Output behaves differently in 7+
5. You want to write a script that uses a feature only available in PowerShell 7+, but your script might run on 5.1. How should you check the version before running the feature?
hard
A. Use if ($PSVersionTable.PSVersion -eq 7) { # run feature }
B. Use if ($PSVersionTable.Version -gt 7) { # run feature }
C. Use if ($PSVersionTable.PSVersion.Major -ge 7) { # run feature }
D. Use if ($PSVersionTable.PSVersion.Minor -ge 7) { # run feature }
Solution
Step 1: Identify correct property for major version
$PSVersionTable.PSVersion.Major gives the major version number (5 or 7).
Step 2: Use proper comparison operator
Using -ge 7 checks if version is 7 or higher, suitable for feature gating.
Final Answer:
Use if ($PSVersionTable.PSVersion.Major -ge 7) { # run feature } -> Option C
Quick Check:
Check major version with .Major and -ge 7 [OK]
Hint: Check major version with .Major and -ge 7 before running features [OK]
Common Mistakes:
Comparing full version object instead of .Major
Using .Minor instead of .Major for major version check
Using wrong property like $PSVersionTable.Version
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.