Never been more stuck on a script. Running IF inside FOREACH by measurement

I have no bloody idea how to make this work, it seems that the 2nd part just executes on my local machine and the $entry in $average doesnt work, or more specifically, there are no $entries just 1 average. Is the logic wrong ?

 

Not sure how to insert this as “powershell” into the forum

$computers = (gc C:\temp\computers.txt).split(“,”)

$average = invoke-command -computerName $computers -scriptblock {

 

(Get-Ciminstance Win32_ReliabilityStabilityMetrics |
Measure-Object -Average systemStabilityIndex | select average)}

foreach ($entry in $average){
if ($entry.average -lt 5) {

invoke-command -computerName $computers -scriptblock {get-wmiobject Win32_ReliabilityRecords -property Message |
select-object -first 2 Message | format-list *}
}}

solved.

 

I’m an idiot because I ran the 2nd part of the script with same invoke command and $computers variable…

It now works great

 

$computers = (gc C:\temp\computers.txt).split(“,”)

$average = invoke-command -computerName $computers -scriptblock {

(Get-Ciminstance Win32_ReliabilityStabilityMetrics |
Measure-Object -Average systemStabilityIndex | select average)}



foreach ($entry in $average){ 
if ($entry.average -lt 5) {

get-wmiobject Win32_ReliabilityRecords -property Message | 
select-object -first 10 Message | format-list *}}