Beans have always been a misunderstanding, always think of PowerShell remote operation, if a command comes with-computername parameters, then use him well, this comes with the positive efficiency than I use Invoke-command remote call strong. Today, no intention to turn over the textbook, only to find this understanding is wrong! I've written a 1-year script with this kind of error ~650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0041.gif "alt=" J_0041.gif "/>
Beans actually verified, for example, I query 5 computers the latest 200 log records, the following two statements can achieve similar results.
Get-eventlog-computername sydit01,sydav01,sydwsus,melfs01,melfs02-logname application-newest Invoke-command- ComputerName sydit01,sydav01,sydwsus,melfs01,melfs02-scriptblock{get-eventlog-logname application-newest 200}
I can use Measure-command to estimate the execution time and see if the difference is obvious. The first command uses its own-computername for 35 seconds, and the second command takes 11 seconds, almost 3 times times more than the difference
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7C/B1/wKioL1bWdkiBGDSyAAAv7n0RubI560.png "style=" float: none; "title=" 10.PNG "alt=" Wkiol1bwdkibgdsyaaav7n0rubi560.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7C/B1/wKioL1bWdlOwYUN_AAA3EncTsG8844.png "style=" float: none; "title=" 11.PNG "alt=" Wkiol1bwdlowyun_aaa3enctsg8844.png "/>
Why is that?
The simple difference, if the use of-computername, all the commands are in accordance with the order of the computer execution, similar to the effect of foreach, and Invoke-command can be operated by default 32 computers;
The second important difference is that the former does not use the WinRM service, but rather uses a. NET protocol that may be blocked by firewalls.
The third important difference is that the former does not show the properties of the Pscomputername, and it is difficult to tell the difference from where it came from, while the latter makes it easy to distinguish which computer the data comes from;
4th, if I filtered through where-object in the back of the pipeline, the former would pass all the results back to the local unit and then filter, and the latter could be filtered in the Scriptblock and then returned to the results. This is very similar to the difference between-filter and Where-object.
To sum up, in general, the use of INVOKE-COMMNAD efficiency is much higher.
This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1746701
Efficiency comparison of Powershell Invoke-command Vs-computername