我有两个循环:
$computer = $args[0]
$colProcData = @()
$procs = get-process -computername $computer | sort -descending "WorkingSet" | select -first 3
foreach($proc in $procs)
{
$machine = $proc.MachineName
$process = [String]$proc.ProcessName
$WorkingSet = [int64]($proc.WorkingSet64/1024)
$id = $proc.Id
$CPU = ($proc.CPU)
$procdata = new-object psobject
$procdata | add-member noteproperty machine $machine
$procdata | add-member noteproperty process $process
$procdata | add-member noteproperty usedRam-MB $WorkingSet
$procdata | add-member noteproperty id $id
$procdata | add-member noteproperty CPU $CPU
$colProcData += $procdata
}
$colProcData | Sort-Object usedRam-MB -descending | Format-Table -AutoSize | out-default
$colProcData = @()
$procs = get-process -computername $computer | sort -descending "WorkingSet" | select -last 3
foreach($proc in $procs)
{
$machine = $proc.MachineName
$process = [String]$proc.ProcessName
$WorkingSet = [int64]($proc.WorkingSet64/1024)
$id = $proc.Id
$CPU = ($proc.CPU)
$procdata = new-object psobject
$procdata | add-member noteproperty machine $machine
$procdata | add-member noteproperty process $process
$procdata | add-member noteproperty usedRam-MB $WorkingSet
$procdata | add-member noteproperty id $id
$procdata | add-member noteproperty CPU $CPU
$colProcData += $procdata
}
$colProcData | Sort-Object usedRam-MB -descending | Format-Table -AutoSize | out-default
唯一的区别是第一个/最后一个。当我运行“ .\scriptName.ps1 systemName
”时,我得到:
process usedRam-MB id CPU
------- ---------- -- ---
mysqld 135812 1692
WmiPrvSE 79560 6184
powershell 51724 6644
process usedRam-MB id CPU
------- ---------- -- ---
LogonUI 264 580
Idle 24 0
sqlservr -1987392 1640
我怎样才能摆脱那个减号?仅供参考:systemName 是远程计算机,而不是 localhost!如果我在 localhost 上运行它,我不会得到任何减号:
process usedRam-MB id CPU
------- ---------- -- ---
mysqld 135888 1692
WmiPrvSE 80508 6184
svchost 50720 832
process usedRam-MB id CPU
------- ---------- -- ---
sqlservr 10618744 1640
LogonUI 264 580
Idle 24 0
也供参考:
systemName 上的内存总量:12.000 MB
请帮忙。