PowerShell Utility Commands (2)

Source: Internet
Author: User

I came again, today to share the practical command is Measure-object, look at the text of this command to know is used for statistical evaluation of the object, then we say his specific use

First we can look at the syntax of this command to see what parameters he can support

PS C:\Windows\system32> Get-Command measure-Object -SyntaxMeasure-Object [[-Property] <string[]>] [-InputObject <psobject>] [-Sum] [-Average] [-Maximum] [-Minimum] [<CommonParameters>]Measure-Object [[-Property] <string[]>] [-InputObject <psobject>] [-Line] [-Word] [-Character] [-IgnoreWhiteSpace] [<CommonParameters>]

From the above we can see that measure-object can support summing, averaging, taking the maximum value, taking the minimum, counting the number of rows, the number of words, the number of characters, the Ignorewhitespace parameter is to let you in the statistical time ignore the white space character (space, carriage return) count.
Let's examine these features separately in code.

PS c:\windows\system32> get-process | Measure-property Vm-maximumcount:210average:sum:maximum:2238980472832minimum:property:vmps C:\Win Dows\system32> get-process | Measure-property Vm-minimumcount:210average:sum:maximum:minimum:4096property:vmps C:\Windows\syst Em32> get-process | Measure-property vm-averagecount:214average:1596722333006.95sum:maximum:minimum:property:vmps c \ Windows\system32> get-process | Measure-property Vm-sumcount:212average:sum:337291811336192maximum:minimum:property:vmps C:\Windo ws\system32> get-content D:\File1.txt |         Measure-line-word-characterlines Words Characters Property----------------------------4 20 113 PS c:\windows\system32> get-content D:\File1.txt |         Measure-line-word-character-ignorewhitespacelines Words Characters Property----------------------------4 20 PS C:\Windows\system32> get-content D:\File1.txtLearning PowerShell Technologyi like PowerShell Script Languagedo you like it as Mefine, l Et ' s learn it togather

The above code shows the function of Measure-object, ask you, strong not strong, not bad, do not need to call Max, a call min, direct a command to take care of all

Another more practical Measure command, Measure-command, this command is often used to detect the running time of the code, through this time, we can evaluate which code is more excellent, the time required to improve the efficiency of our code execution, Reduce the performance loss of the running Code host

$Script1={For($i=0;$i -le 100;$i++){Add-Content -Path D:\File1.txt -Value "I want add some word in this file"}}$Script2={$NW=New-Object System.IO.StreamWriter "d:\file1.txt"; For($i=0;$i -lt 100;$i++){$NW.WriteLine("I Write it again !")};$nw.Close()}PS C:\Windows\system32> Measure-Command -Expression $Script1 | select TotalMillisecondsTotalMilliseconds-----------------         117.5692PS C:\Windows\system32> Measure-Command -Expression $Script2 | select TotalMillisecondsTotalMilliseconds-----------------           2.5188

The same results can be evaluated by Measure-command, but the code is different, and the time spent is completely dissimilar, which allows us to see if our code is good.

Well, today introduced to this, melon seeds peanut beer, sir to a copy?

PowerShell Utility Commands (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.