Bird
0
0

What will this code output?

medium📝 Command Output Q5 of 15
PowerShell - Working with Objects
What will this code output?
$obj = [PSCustomObject]@{Fruit='Apple'; Quantity=5}; $obj | Select-Object Fruit
AError: Select-Object requires -Property
BFruit Quantity ----- -------- Apple 5
CQuantity -------- 5
DFruit ----- Apple
Step-by-Step Solution
Solution:
  1. Step 1: Create PSCustomObject with Fruit and Quantity

    The object has Fruit='Apple' and Quantity=5.
  2. Step 2: Use Select-Object to select Fruit property

    Select-Object Fruit outputs only the Fruit property and its value.
  3. Step 3: Output shows Fruit with value Apple

    Quantity is excluded from output.
  4. Final Answer:

    Fruit ----- Apple -> Option D
  5. Quick Check:

    Select-Object filters properties = Fruit ----- Apple [OK]
Quick Trick: Select-Object picks only requested properties from objects [OK]
Common Mistakes:
  • Expecting all properties to show
  • Confusing Select-Object syntax
  • Assuming error without -Property parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes