0
0
PowerShellscripting~20 mins

Arrays in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Arrays Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell array operation?
Consider the following PowerShell code snippet. What will be the output after running it?
PowerShell
$arr = 1,2,3,4,5
$arr[1..3]
A2 3 4
B3 4 5
C1 2 3
D1 3 5
Attempts:
2 left
💡 Hint
Remember that array slicing with [start..end] includes both start and end indices.
📝 Syntax
intermediate
2:00remaining
Which option correctly creates an array of strings in PowerShell?
Select the option that correctly creates an array containing the strings "apple", "banana", and "cherry".
A$fruits = {'apple', 'banana', 'cherry'}
B$fruits = ['apple', 'banana', 'cherry']
C$fruits = @('apple', 'banana', 'cherry')
D$fruits = array('apple', 'banana', 'cherry')
Attempts:
2 left
💡 Hint
PowerShell uses @() to create arrays.
🔧 Debug
advanced
2:00remaining
Why does this PowerShell array code produce an error?
The following code is intended to add an element to an existing array, but it causes an error. What is the reason?
PowerShell
$arr = 1,2,3
$arr += 4
$arr[3]
AError because arrays in PowerShell are fixed size and cannot be appended
BNo error occurs; output is 4
CError because += operator is not valid for arrays
DError because $arr[3] is out of range
Attempts:
2 left
💡 Hint
Try running the code in PowerShell to see the actual behavior.
🚀 Application
advanced
2:00remaining
How to filter an array to only even numbers in PowerShell?
Given an array $numbers = 1..10, which option correctly filters it to only even numbers?
PowerShell
$numbers = 1..10
A$even = $numbers | Where-Object { $_ % 2 -eq 0 }
B$even = $numbers.Where({ $_ % 2 -eq 0 })
C$even = $numbers | Filter { $_ % 2 -eq 0 }
D$even = $numbers | Select-Object { $_ % 2 -eq 0 }
Attempts:
2 left
💡 Hint
Use the correct cmdlet for filtering in PowerShell pipelines.
🧠 Conceptual
expert
3:00remaining
What is the length of the array after this PowerShell operation?
Given the code below, what is the length of $arr after execution?
PowerShell
$arr = 1,2,3
$arr = $arr + @(4,5)
$arr = $arr[1..3]
A2
B5
C4
D3
Attempts:
2 left
💡 Hint
Track the array length after each operation carefully.