Get CPU average on remote servers

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 7 months ago.

  • Author
    Posts
  • #5593

    by rcjay272 at 2013-02-25 23:00:54

    I am having an issue with running this command. It gives me a runtime error just after the .invoke() and I don't know why. I can run the same chunk of code against a single server just fine.

    Can you point me in the right direction as to why I can run it against multiple servers?

    $servers = Get-Content -Path C:\Env2_TS_Servers.txt
    ForEach ($server in $servers)
    {
    [string]{
    $Server
    (get-counter -computername $server -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 5 |
    select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average}
    .lines}.invoke()
    }

    I can run this command against a single server....

    (get-counter -computername ts10 -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 5 |
    select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average

    OUTPUT
    PS C:\Load_Stuff\MonitoringScripts\PowerShell> .\CPU_Useage.ps1
    2.15259170793501

    by ArtB0514 at 2013-02-26 08:11:42

    This worked for me:

    (get-counter -computername ts10 -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 5 |
    foreach {$_.CounterSamples.CookedValue} | Measure-Object -Average).average

You must be logged in to reply to this topic.