Powershell - Measure-Object Cmdlet


Advertisements

Cmdlet

Measure-Object cmdlet can be used to get the properties of the passed output such as min, max, size, count, line etc.

In these examples, we're see the Measure-Object cmdlet in action.

Example 1

In this example, first we've a file test.txt in D:\temp\test with content "Welcome to TutorialsPoint.Com".

Type the following command in PowerShell ISE Console

get-content D:\temp\test\test.txt | measure-object -character -line -word

Output

You can see following output in PowerShell console.

   Lines                   Words              Characters Property               
   -----                   -----              ---------- --------               
     1                       3                      29    

Example 2

In this example, We'll count the no. of files present in current directory.

Type the following command in PowerShell ISE Console

Get-ChildItem | Measure-Object

Output

You can see following output in PowerShell console.

 Count    : 25
 Average  : 
 Sum      : 
 Maximum  : 
 Minimum  : 
 Property : 
powershell_advanced_cmdlets.htm
Advertisements