Challenge - 5 Problems
PowerShell Version Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
PowerShell Version Output
What is the output of this command in PowerShell 7+?
$PSVersionTable.PSVersion.MajorPowerShell
$PSVersionTable.PSVersion.Major
Attempts:
2 left
💡 Hint
Check the major version number property in PowerShell 7+.
✗ Incorrect
In PowerShell 7 and later, the major version number is 7, so the command outputs 7.
📝 Syntax
intermediate2: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>Attempts:
2 left
💡 Hint
PowerShell 7+ supports the ternary operator with ? : syntax and uses -gt for greater than.
✗ Incorrect
Option B uses the correct ternary syntax with PowerShell comparison operator -gt. Option B is a valid if-else but not ternary. Option B uses invalid operator >. Option B uses invalid syntax.
🔧 Debug
advanced2:00remaining
Why does this script fail in PowerShell 5.1 but work in 7+?
Given this script:
Why does it fail in PowerShell 5.1 but work in 7+?
1..5 | ForEach-Object { $_.ToString() -replace '^', 'Num-' }Why does it fail in PowerShell 5.1 but work in 7+?
Attempts:
2 left
💡 Hint
Check how ToString() output interacts with -replace in different versions.
✗ Incorrect
In PowerShell 5.1, the pipeline object is an integer and ToString() returns a string, but the -replace operator expects a string input. Sometimes implicit conversions cause issues. In PowerShell 7+, the pipeline and string handling is improved, so this works smoothly.
🧠 Conceptual
advanced1:30remaining
Cross-platform Compatibility in PowerShell Versions
Which statement best describes the cross-platform support differences between PowerShell 5.1 and PowerShell 7+?
Attempts:
2 left
💡 Hint
Consider which PowerShell version introduced cross-platform support.
✗ Incorrect
PowerShell 5.1 is the last Windows-only version. PowerShell 7+ is built on .NET Core and supports Windows, Linux, and macOS natively.
🚀 Application
expert2: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?
Attempts:
2 left
💡 Hint
Check the comparison operators and logic for version numbers.
✗ Incorrect
Option D correctly checks if major version is 7 or higher for modern, else legacy. Option D reverses logic. Option D reverses legacy and modern. Option D reverses logic and labels.