Skip to content
2008/05/01 / Koen Vermoesen

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 ;-)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 86 other followers