Measure-Object -Property capacity -Sum

问题描述 投票:0回答:1

我尝试了下面的命令来获取计算机的内存使用情况,但得到的错误是无限或NaN。

    $Totalsizemem=gwmi Win32_PhysicalMemory | Measure-Object -Property capacity -Sum | Foreach {" 
    {0:N2}" -f ([math]::round(($_.Sum / 1GB),2))}
    gwmi -computername localhost Win32_Process | Sort WorkingSetSize -Descending | Select 
    Name,@{n="Memoryusage(%)";Expression ={[math]::round(($_.WorkingSetSize / 1GB),1) / 
    $Totalsizemem*100}} | Select -First 10 | Format-Table -AutoSize | Out-Default

预期的输出是 -

    Name                                              Memoryusage(%)
    ----                                              --------------

    powershell_ise.exe                             0.655737704918033
    explorer.exe                                   0.655737704918033
    explorer.exe                                   0.655737704918033
    explorer.exe                                   0.655737704918033

但我得到的输出 -

    Name                 Memoryusage(%)
    ----                 --------------
    powershell_ise.exe                ∞
    svchost.exe                       ∞
    explorer.exe                    NaN
    svchost.exe                     NaN
    explorer.exe                    NaN

有谁知道如何纠正这个问题?

powershell memory-management get-wmiobject
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.