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


