PowerTip: Find the Largest Number in a PowerShell Array

Summary: Easily find the largest number in a Windows PowerShell array.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily find the largest number in an array of numbers?

Hey, Scripting Guy! Answer Pipe the array to the Measure-Object cmdlet, and use the –Maximum switch:

PS C:\> $a = [array]1,2,5,6,3,2,9,1

PS C:\> $a | measure -Maximum

 

Count    : 8

Average  :

Sum      :

Maximum  : 9

Minimum  :

Property :