Tuesday, May 12, 2015

#70 : Show statistical information using Powershell

Today' we will talk about Measure-Object cmdlet which helps you peforming average, max, min and other operations. Before we perform some tests, we need to create a file with some data. My file is as follows :

name,age
Som,25
Ravi,30
Akash,60
Jack,89
John,16


Save the above as file.csv. You can use below command to see the statistics :

import-csv C:\engg.demo\file.csv | measure-object age -ave -max -min

Output:
Count    : 3
Average  : 38.3333333333333
Sum      :
Maximum  : 60
Minimum  : 25
Property : age


In measure-object, we mentioned the column name against which you want to run certain operation. After that, you can mention from below :
-ave : Average
-min : Min
-max : Max
-sum : Sum

Enjoy scripting!!

 

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...