Challenge - 5 Problems
Sort-Object Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Sort-Object command?
Given this PowerShell command, what will be the output?
PowerShell
1..5 | Sort-Object -DescendingAttempts:
2 left
💡 Hint
Think about what -Descending does to a list of numbers.
✗ Incorrect
Sort-Object with -Descending sorts the numbers from highest to lowest, so 5 4 3 2 1.
💻 Command Output
intermediate2:00remaining
What does this Sort-Object command output?
What is the output of this command?
PowerShell
'apple','banana','cherry' | Sort-Object Length
Attempts:
2 left
💡 Hint
Sort by the length of each word from shortest to longest.
✗ Incorrect
Sort-Object Length sorts strings by their length ascending: apple(5), banana(6), cherry(6). Since banana and cherry have same length, original order is preserved for them.
📝 Syntax
advanced2:00remaining
Which option correctly sorts objects by a property in descending order?
You have objects with a property 'Age'. Which command sorts them descending by Age?
PowerShell
$people = @(@{Name='Ann';Age=30}, @{Name='Bob';Age=25}, @{Name='Cara';Age=35})Attempts:
2 left
💡 Hint
Check the correct syntax for Sort-Object parameters.
✗ Incorrect
Option A uses correct parameter names: -Property Age and -Descending switch. Others have syntax errors or invalid parameters.
🚀 Application
advanced2:00remaining
How to sort files by LastWriteTime descending?
You want to list files sorted by last modified date, newest first. Which command works?
PowerShell
Get-ChildItem | ???
Attempts:
2 left
💡 Hint
Use the correct parameter names and switches for Sort-Object.
✗ Incorrect
Only option D uses correct syntax with -Property and -Descending switch. A lacks '-' before Descending, making it invalid.
🧠 Conceptual
expert2:00remaining
What error does this Sort-Object command raise?
What error occurs when running this command?
PowerShell
1..5 | Sort-Object -Property NonExistentPropertyAttempts:
2 left
💡 Hint
Think about what happens if you sort by a property that does not exist.
✗ Incorrect
Sort-Object throws a PropertyNotFoundException when the property does not exist on the objects.