Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The property 'Name' is accessed using $_.Name to get each object's Name value.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names like 'Value' or 'Object'.
Not using a hashtable syntax.
✗ Incorrect
To add a new object with property 'Name', use @{Name='David'}.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-eq' which checks exact equality.
Using '-like' without wildcards.
Using '-contains' which is for collections.
✗ Incorrect
The operator '-match' is used to match a regex pattern like '^A'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different property names like 'Value' or 'Years' inconsistently.
Using property names that do not match.
✗ Incorrect
The property for age is 'Age' in both objects.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names or operators.
Trying to uppercase the Age property.
✗ Incorrect
Filter by Age > 28 and convert the Name property to uppercase.