$Processes = get-process -computername $tag1 | Group-Object -Property ProcessName
foreach($Process in $Processes)
{
$Obj = New-Object psobject
$Obj | Add-Member -MemberType NoteProperty -Name Name -Value $Process.Name
$Obj | Add-Member -MemberType NoteProperty -Name Mem -Value ($Process.Group|Measure-Object WorkingSet -Sum).Sum
$Obj
}
当前,它以字节为单位显示内存使用情况,如何更改显示类似以下内容:
76,592 KB
并输出所有自动调整的大小? (向左对齐)
最佳答案
Format-Table可以显示表达式并自动调整列大小以适合结果:
在64位上:
get-process -computername $tag1 | Group-Object -Property ProcessName |
Format-Table Name, @{n='Mem (KB)';e={'{0:N0}' -f (($_.Group|Measure-Object WorkingSet64 -Sum).Sum / 1KB)};a='right'} -AutoSize
在32位上:get-process -computername $tag1 | Group-Object -Property ProcessName |
Format-Table Name, @{n='Mem (KB)';e={'{0:N0}' -f (($_.Group|Measure-Object WorkingSet -Sum).Sum / 1KB)};a='right'} -AutoSize
关于powershell - 获取进程与总内存使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26552223/