Measure-Object -sum convert to MB

Hello, PW newbie here. I’m running this code which works fine:
Get-Process | Where-Object {$_.name -notlike ‘powershell’ -or ‘pwsh*’} | Sort-Object -Property vm -Descending | Select-Object -First 10 | Measure-Object vm -sum

However, I’m trying to display the sum in MB so I’ve tried running the following which doesn’t work:
Get-Process | Where-Object {$.name -notlike ‘powershell’ -or ‘pwsh*’} | Sort-Object -Property vm -Descending | Select-Object -First 10 | Measure-Object -Property vm -sum {$.sum/1mb}

Any and all insight would be most appreciated. TY

You have a typo in your second command. $.name should be $_.name. but also sum doesn’t take a formula. One way would be

$Measurement = (Get-Process | Where-Object {$_.name -notlike ‘powershell’ -or ‘pwsh*’} | Sort-Object -Property vm -Descending | Select-Object -First 10 | Measure-Object -Property vm -sum)
"$($Measurement.Sum / 1MB)MB"
2 Likes

Thank you. Much appreciated.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.