开发者

Powershell: Is it possible to set-alias on a piped command?

开发者 https://www.devze.com 2022-12-12 06:05 出处:网络
I would like to set the fol开发者_如何学JAVAlowing alias up in my powershell profile: set-alias mem-users get-process | ? {($_.PM -gt 10000000) -or ($_.VM -gt 10000000)} | sort -property PM

I would like to set the fol开发者_如何学JAVAlowing alias up in my powershell profile:

set-alias mem-users get-process | ? {($_.PM -gt 10000000) -or ($_.VM -gt 10000000)} | sort -property PM

But when I try this out and call mem-users I just get the results of get-process. How would I set this up? Do I have to write a custom function? The examples for set-alias show a piped command working with the -passThru parameter but I can't get it to work.


Aliases are just that - a name substitute and nothing more. What you want is a function:

function mem-hogs
{
    get-process | ? {($_.PM -gt 10000000) -or ($_.VM -gt 10000000)}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消