How do I return only the integer sum of Measure-Object in PowerShell?

前端 未结 3 1233
梦如初夏
梦如初夏 2020-12-11 01:12

If I run the following command in PowerShell, it will return to me an object with the sum of the WorkingSet property:

PS > get-process chrome | measure-ob         


        
3条回答
  •  不思量自难忘°
    2020-12-11 01:50

    Yes, use Select-Object:

    Get-Process chrome | Measure-Object WorkingSet -sum | Select-Object -expand Sum
    

    Select-Object is used when one needs only some properties from the original object. It creates a new object and copies the desired properties to the new one.

    Get-Process | Select-Object -property ProcessName, Handles
    

    In case you need to extract the value (from one property), you use parameter -expandProperty instead of -property:

    Get-Process | Select-Object -expand ProcessName
    

    Note that you can compute the returned value:

    get-process | Select-Object -property @{Name='descr'; Expression={"{0} - {1}" -f $_.ProcessName, $_.Handles }}
    

提交回复
热议问题