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.by ArtB0514 at 2013-02-26 08:11:42
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
This worked for me:(get-counter -computername ts10 -Counter "\Processor(Total)% Processor Time" -SampleInterval 1 -MaxSamples 5 |
foreach {$.CounterSamples.CookedValue} | Measure-Object -Average).average