ListTopProcesses.ps1

After having received a splendid presentation on PowerShell from a couple of my colleagues (Rastix, Virtix and others…) it was time to write my first script myself. After fiddling around a couple of hours I came up with a script to list a top 10 of memory consuming processes on a remote computer:

function PrintMegs
{
[Math]::Truncate($args[0]/1MB)
}

get-wmiobject -class win32_process -computername $args[0] | Sort-Object vm -desc | Select-Object -first 10 | Format-Table ProcessName,@{Label=”VM (MB)”;Expression={PrintMegs($_.VM)}},@{Label=”WS (MB)”;Expression={PrintMegs($_.WS)}},Handles,ProcessID,Path -autosize

The script takes one input parameter; the name of the computer, it does work with “localhost” also though.

The hardest part was figuring out how to print the memroy details in MB, with no decimal places and in table format ;-)

About these ads

http://blog.koenvermoesen.be/about-koen/

Tagged with:
Posted in Scripting
Pro-Exchange / Pro-Lync / Pro-Office365

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 155 other followers

Follow

Get every new post delivered to your Inbox.

Join 155 other followers

%d bloggers like this: