Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Powershell utility commands (2)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Here I go again. The practical command I share with you today is Measure-Object. If you look at the literal meaning of this command, you can see that it is used for statistical evaluation objects. Let's talk about its specific usage.

First of all, we can look at the syntax of this command and see which parameters it can support.

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

From the above we can see that Measure-Object can support summation, average, take the maximum value, take the minimum value, count the number of lines, words, characters, IgnoreWhiteSpace parameter is to allow you to ignore the white space character (space, enter) count.

Let's use the code to verify these functions separately.

PS C:\ Windows\ system32 > Get-Process | measure-Property vm-MaximumCount: 210Average: Sum: Maximum: 2238980472832Minimum: VMPS C:\ Windows\ system32 > Get-Process | measure-Property vm-MinimumCount: 210Average: Sum: Maximum: Minimum: 4096Property: VMPS C:\ Windows\ system32 > Get-Process | measure-Property vm-AverageCount: 214Average: 1596722333006.95Sum: Maximum: Minimum: Property: VMPS C:\ VMPS\ VMPS > VMPS | | measure-Property vm-sumCount: 212Average: Sum: 337291811336192Maximum: Minimum: Property: VMPS C:\ Windows\ 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 97 PS C:\ Windows\ system32 > Get-Content D:\ File1.txtLearning Powershell TechnologyI like Powershell Script LanguageDo you like it as meFine Let's learn it togather

The above code shows the function of Measure-Object. I ask you whether it is strong and powerful. You don't need to call max and min for a while, and you can get all done with one command.

Let's introduce another practical Measure command, Measure-Command, which is often used to detect the running time of code. Through this time, we can evaluate which kind of code is better and take less time, improve the execution efficiency of our code, and reduce the performance loss of the host running the code.

$Script1= {For ($iposit / I-le 100 +) {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 ($NW.WriteLine / "I Write it again!") {$NW.WriteLine $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 result can be evaluated through Measure-Command, but the time spent is completely different because the code is different, which makes us know whether our code is good or not.

All right, that's all for today. Guazi Peanut Beer, guest?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report