Challenge - 5 Problems
PowerShell Object Arrays Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of creating and accessing object arrays
What is the output of this PowerShell script?
PowerShell
$arr = @()
$arr += [PSCustomObject]@{Name='Alice'; Age=30}
$arr += [PSCustomObject]@{Name='Bob'; Age=25}
$arr[1].NameAttempts:
2 left
💡 Hint
Remember arrays start at index 0.
✗ Incorrect
The array has two objects. Index 1 is the second object with Name 'Bob'.
📝 Syntax
intermediate2:00remaining
Correct syntax to create an array of objects
Which option correctly creates an array of two objects with properties Name and Age?
Attempts:
2 left
💡 Hint
Use @() to create an array and @{} to create objects.
✗ Incorrect
Option B correctly uses @() for array and [PSCustomObject]@{} for objects.
🔧 Debug
advanced2:00remaining
Identify the error in adding objects to an array
What error does this script produce?
$arr = @()
$arr += @{Name='Anna'; Age=28}
$arr[0].Name
Attempts:
2 left
💡 Hint
Check the type of object added to the array.
✗ Incorrect
The script adds a hashtable, not a PSCustomObject, so accessing .Name fails.
🚀 Application
advanced2:00remaining
Filter object array by property value
Given an array of objects with property Age, which command returns only objects where Age is greater than 30?
Attempts:
2 left
💡 Hint
Use Where-Object with a script block and $_ for current object.
✗ Incorrect
Option A uses correct syntax with Where-Object and $_ to filter by Age.
🧠 Conceptual
expert2:00remaining
Understanding object array property modification
If you modify a property of an object inside a PowerShell array, what happens to the array?
Attempts:
2 left
💡 Hint
Think about how PowerShell handles objects in arrays.
✗ Incorrect
PowerShell arrays hold references to objects, so modifying an object changes it inside the array.