tags:

views:

54

answers:

1

I would like to set the following 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.

+5  A: 

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)}
}
Keith Hill
hehehe mem-hogs why didn't I think of that!?
George Mauer
+1 for mem-hogs
Martinho Fernandes
There's a missing brace at the end of the boolean check there
Dan Fitch
Fixed. Thanks for the heads-up on the missing brace.
Keith Hill