Measuring objects in PowerShell 3.0

Monday, April 9, 2012

The Measure-Object cmdlet gives us a great way to find minimum and maximum values in a collection of objects. For example, if we want to know the smallest and largest size of a file in the current directory: PS> Get-ChildItem | Measure-Object -Property Length -Minimum -Maximum Count : 2751 Average : Sum : Maximum : 56297240 Minimum : 35 Property : Length In PowerShell 2.0 it only worked with numeric properties (integers), we couldn't use it to compare properties like LastWriteTime (DateTime). In PowerShell 3.0 we can now use...
one comment

Select and then Sort

Thursday, May 29, 2008

  When you use both select-object and sort-object in a pipeline, what's the proper order? Let's check how fast they execute. Each speed test is built from two similar commands with a different sort/select piping order and each test is executed 10 times. The total execution time is measured in Milliseconds.   - Updated: 06/11/2008 (see comment below by Lee Holmes) -   Test #1 PS > (measure-Command { 1..10 | foreach { gsv | sort name | select name,status }}).TotalMilliseconds 444.5451 PS > (measure-Command { 1..10 | foreach { gsv | select name,status | sort name}}).TotalMilliseconds 384.7565 Result: Second command is...
no comments