0
0
PowerShellscripting~20 mins

PowerShell versions (5.1 vs 7+) - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Version Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
PowerShell Version Output
What is the output of this command in PowerShell 7+?

$PSVersionTable.PSVersion.Major
PowerShell
$PSVersionTable.PSVersion.Major
A7
B5
C6
DError: Property not found
Attempts:
2 left
💡 Hint
Check the major version number property in PowerShell 7+.
📝 Syntax
intermediate
2:00remaining
Using Ternary Operator in PowerShell 7+
Which option correctly uses the ternary operator introduced in PowerShell 7+ to assign a value to $result based on $x?
PowerShell
$x = 10
$result = <fill_here>
A$result = if ($x -gt 5) { 'Greater' } else { 'Smaller' }
B$result = $x -gt 5 ? 'Greater' : 'Smaller'
C$result = $x > 5 ? 'Greater' : 'Smaller'
D$result = $x -gt 5 then 'Greater' else 'Smaller'
Attempts:
2 left
💡 Hint
PowerShell 7+ supports the ternary operator with ? : syntax and uses -gt for greater than.
🔧 Debug
advanced
2:00remaining
Why does this script fail in PowerShell 5.1 but work in 7+?
Given this script:
1..5 | ForEach-Object { $_.ToString() -replace '^', 'Num-' }

Why does it fail in PowerShell 5.1 but work in 7+?
ABecause the -replace operator does not exist in PowerShell 5.1
BBecause in PowerShell 5.1, the pipeline variable $_ is not available inside script blocks
CBecause in PowerShell 5.1, the ToString() method returns a different type that cannot be used with -replace
DBecause in PowerShell 5.1, the -replace operator does not support regex anchors like '^'
Attempts:
2 left
💡 Hint
Check how ToString() output interacts with -replace in different versions.
🧠 Conceptual
advanced
1:30remaining
Cross-platform Compatibility in PowerShell Versions
Which statement best describes the cross-platform support differences between PowerShell 5.1 and PowerShell 7+?
APowerShell 5.1 is Windows-only, while PowerShell 7+ supports Windows, Linux, and macOS natively.
BBoth PowerShell 5.1 and 7+ support Windows and Linux, but only 7+ supports macOS.
CPowerShell 5.1 runs natively on Windows, Linux, and macOS, while PowerShell 7+ only runs on Windows.
DPowerShell 5.1 and 7+ both support only Windows natively; cross-platform support requires extra tools.
Attempts:
2 left
💡 Hint
Consider which PowerShell version introduced cross-platform support.
🚀 Application
expert
2:30remaining
Detecting PowerShell Version in a Script
You want a script that prints 'Legacy PowerShell' if running on version 5.1 or lower, and 'Modern PowerShell' if running on 7 or higher. Which script produces the correct output?
Aif ($PSVersionTable.PSVersion.Major -lt 7) { 'Modern PowerShell' } else { 'Legacy PowerShell' }
Bif ($PSVersionTable.PSVersion.Major -le 5) { 'Legacy PowerShell' } else { 'Modern PowerShell' }
Cif ($PSVersionTable.PSVersion.Major -gt 5) { 'Legacy PowerShell' } else { 'Modern PowerShell' }
Dif ($PSVersionTable.PSVersion.Major -ge 7) { 'Modern PowerShell' } else { 'Legacy PowerShell' }
Attempts:
2 left
💡 Hint
Check the comparison operators and logic for version numbers.