0
0
PowerShellscripting~20 mins

Measure-Object for statistics in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Measure-Object Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Measure-Object with Sum and Average
What is the output of the following PowerShell code snippet?
PowerShell
1..5 | Measure-Object -Sum -Average | Select-Object Sum, Average
A@{Sum=15; Average=2.5}
B@{Sum=10; Average=2.5}
C@{Sum=15; Average=3}
D@{Sum=10; Average=3}
Attempts:
2 left
💡 Hint
Sum is the total of numbers 1 to 5, average is the sum divided by count.
data_output
intermediate
2:00remaining
Count and Maximum Value from Measure-Object
Given the array 3, 7, 2, 9, 5, what does this command output?
PowerShell
3,7,2,9,5 | Measure-Object -Maximum -Count | Select-Object Maximum, Count
A@{Maximum=9; Count=5}
B@{Maximum=9; Count=4}
C@{Maximum=7; Count=4}
D@{Maximum=7; Count=5}
Attempts:
2 left
💡 Hint
Count is the number of items, Maximum is the largest number.
🔧 Debug
advanced
2:00remaining
Identify the error in Measure-Object usage
What error does this code produce?
PowerShell
1..3 | Measure-Object -Sum -Median
ANo error, outputs Sum and Median correctly.
BParameter set cannot be resolved using the specified named parameters.
CRuntime error: Median is not a valid property.
DSyntax error: Missing pipe operator.
Attempts:
2 left
💡 Hint
Check if Measure-Object supports combining Sum and Median parameters.
🚀 Application
advanced
3:00remaining
Calculate Standard Deviation using Measure-Object
Which option correctly calculates the standard deviation of the numbers 4, 8, 6, 5, 3 using Measure-Object and additional code?
A$nums = 4,8,6,5,3; $mean = ($nums | Measure-Object -Sum).Sum / $nums.Count; [math]::Sqrt(($nums | ForEach-Object {($_ + $mean) * ($_ + $mean)} | Measure-Object -Sum).Sum / $nums.Count)
B$nums = 4,8,6,5,3; $mean = ($nums | Measure-Object -Average).Average; [math]::Sqrt(($nums | ForEach-Object {($_ - $mean)} | Measure-Object -Sum).Sum / $nums.Count)
C$nums = 4,8,6,5,3; $mean = ($nums | Measure-Object -Average).Average; [math]::Sqrt(($nums | ForEach-Object {($_ - $mean) * ($_ - $mean)} | Measure-Object -Sum).Sum / $nums.Count)
D$nums = 4,8,6,5,3; $mean = ($nums | Measure-Object -Average).Average; [math]::Sqrt(($nums | ForEach-Object {($_ - $mean) * ($_ - $mean)} | Measure-Object -Sum).Sum / ($nums.Count - 1))
Attempts:
2 left
💡 Hint
Standard deviation uses squared differences from the mean and divides by count minus one for sample SD.
🧠 Conceptual
expert
1:30remaining
Understanding Measure-Object Output Properties
Which property is NOT included in the output of Measure-Object when using the -Average parameter?
AMaximum
BAverage
CCount
DSum
Attempts:
2 left
💡 Hint
Think about which statistics are calculated by default with -Average.