0
嗨我再次運行此腳本多個服務器(initially posted here) &我想獲得每個特定的服務器名稱將出現在結果中。但是現在,我可以獲得標題CPU & Memory Usage
&,然後依次查看每臺服務器的使用情況。請讓我知道如何獲得每個服務器名稱&的結果。CPU和內存使用腳本
$Output = 'C:\temp\Result.txt'
$ServerList = Get-Content 'C:\temp\ServerNames.txt'
$ScriptBLock = {
$CPUPercent = @{
Label = 'CPUUsed'
Expression = {
$SecsUsed = (New-Timespan -Start $_.StartTime).TotalSeconds
[Math]::Round($_.CPU * 10/$SecsUsed)
}
}
$MemUsage = @{
Label ='RAM(MB)'
Expression = {
[Math]::Round(($_.WS/1MB),2)
}
}
Get-Process | Select-Object -Property Name, CPU, $CPUPercent, $MemUsage,
Description |
Sort-Object -Property CPUUsed -Descending |
Select-Object -First 15 | Format-Table -AutoSize
}
foreach ($ServerNames in $ServerList) {
Invoke-Command -ComputerName $ServerNames {Write-Output "CPU & Memory Usage"}
| Out-File $Output -Append
Invoke-Command -ScriptBlock $ScriptBLock -ComputerName $ServerNames |
Out-File $Output -Append
謝謝埃米爾...這一個工作 「Working on $ ServerNames ..」| Out-File $ Output -Append –