just thought of checking about pscustomobject as per yur previous code .
found it is modern approach and give cleaner output so following shud work for multiple computers .
since sessions might run parallely so iam using $env:computername for corresponding session .
$sessions=new-pssession -ComputerName com1,com2,com3
Invoke-Command -Session $sessions -ScriptBlock {
$computerName = $env:COMPUTERNAME
$cpu = Get-WmiObject -ComputerName $computerName -Class win32_processor -ErrorAction Stop
$mem = Get-WmiObject -ComputerName $computerName -Class win32_operatingsystem -ErrorAction Stop
[PSCustomObject]@{
Host = $computerName
CPU = ($cpu.LoadPercentage|Measure-Object -Average).average
Mem = [math]::Round(($mem.TotalVisibleMemorySize -$mem.FreePhysicalMemory)/$mem.TotalVisibleMemorySize * 100)
}
}