0
0
PowerShellscripting~10 mins

Object arrays in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an array of objects with a single property 'Name'.

PowerShell
$array = @(@{Name='Alice'}, @{Name='Bob'}, @{Name='Charlie'})
$array | ForEach-Object { $_.[1] }
Drag options to blanks, or click blank then click option'
AObject
BValue
CName
DItem
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_.Value or $_.Object which do not exist in the objects.
Trying to access the array directly without looping.
2fill in blank
medium

Complete the code to add a new object with Name 'David' to the existing array.

PowerShell
$array += [1]
Drag options to blanks, or click blank then click option'
A@{Name='David'}
B@{Value='David'}
C@{Object='David'}
D@{Item='David'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names like 'Value' or 'Object'.
Not using a hashtable syntax.
3fill in blank
hard

Fix the error in the code to filter objects where Name starts with 'A'.

PowerShell
$filtered = $array | Where-Object { $_.Name [1] '^A' }
Drag options to blanks, or click blank then click option'
A-contains
B-match
C-like
D-eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-eq' which checks exact equality.
Using '-like' without wildcards.
Using '-contains' which is for collections.
4fill in blank
hard

Fill both blanks to create an array of objects with Name and Age properties.

PowerShell
$people = @(@{Name='Eve'; [1]=30}, @{Name='Frank'; [2]=25})
Drag options to blanks, or click blank then click option'
AAge
BValue
CYears
DCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using different property names like 'Value' or 'Years' inconsistently.
Using property names that do not match.
5fill in blank
hard

Fill all three blanks to create a filtered array of people older than 28 with their names in uppercase.

PowerShell
$result = $people | Where-Object { $_.[1] [2] 28 } | ForEach-Object { $_.[3].ToUpper() }
Drag options to blanks, or click blank then click option'
AAge
B>
CName
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names or operators.
Trying to uppercase the Age property.