Bird
0
0

What is the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Cmdlets and Pipeline
What is the output of this PowerShell code?
$data = @( @{Name='John'; Age=30}, @{Name='Anna'; Age=25}, @{Name='Mike'; Age=35} )
$data | Sort-Object Age | ForEach-Object { $_.Name }
AAnna, John, Mike
BJohn, Anna, Mike
CMike, John, Anna
DAnna, Mike, John
Step-by-Step Solution
Solution:
  1. Step 1: Understand sorting by Age property

    The code sorts the array of objects by the Age property in ascending order: 25, 30, 35.
  2. Step 2: Map sorted objects to their Name property

    After sorting, the names in order are Anna (25), John (30), Mike (35).
  3. Final Answer:

    Anna, John, Mike -> Option A
  4. Quick Check:

    Sort by Age ascending = Anna, John, Mike [OK]
Quick Trick: Sort-Object defaults to ascending order [OK]
Common Mistakes:
  • Assuming Sort-Object sorts descending by default
  • Mixing up property names
  • Not accessing the Name property after sorting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes