Thursday, June 7, 2007

PowerShell Remoting example

Just an example of running the new PowerShell Remoting product from /n software

What I'm doing below is SSH'ing to a remote server to run a single command.  I'm returned an object which I then use to further parse after.

I'm just querying a remote server for win32_processor to get the average load percentage of each CPU (4 in this example).

I could easily pump this value into something like PowerGadgets to keep an eye on the CPU utilization.

84# $load=invoke-ssh -server xxxx -user xxxx -password xxxx -command "gwmi win32_
processor" -timeout 30
Do you want to trust the certificate presented?
The server has presented the key below:
Fingerprint: B8:C5:E0:AA:AB:48:D4:F9:3D:D6:5B:FD:9C:5B:40:B6
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
85# ($load|%{if($_.text -like "*loadpercentage*"){$_.text}}).count
4
86# $load|%{if($_.text -like "*loadpercentage*"){[int]$loadt+=[int]$_.text.split(':')[1]}}
87# $loadt/4
1