Find the Median Value

# sort array
$NumberArray = $NumberArray | Sort-Object
if ($NumberArray.count%2) {
    # if odd
    $medianvalue = $NumberArray[[math]::Floor($NumberArray.count/2)]
}
else {
    # if even
    $MedianValue = ($NumberArray[$NumberArray.Count/2],$NumberArray[$NumberArray.count/2-1] | Measure-Object -Average).average
}
$MedianValue
Details
Use this snippet to compute the median from an array of numerical values

Example
PS C:\> $NumberArray = 1,2,3,4,5
>> $NumberArray = $NumberArray | Sort-Object
>> if ($NumberArray.count%2) {
>>     # if odd
>>     $medianvalue = $NumberArray[[math]::Floor($NumberArray.count/2)]
>> }
>> else {
>>     # if even
>>     $MedianValue = ($NumberArray[$NumberArray.Count/2],$NumberArray[$NumberArray.count/2-1] | Measure-Object -Average).average
>> }
>> $MedianValue

3