R
Romance Of Love
Guest
Guest
recently got my hands on the Windows PowerShell RC2 release, and darn, i'm impressed.Made a simple tasklist script:
to test the code, you can go here:
https://connect.microsoft.com/site/s...aspx?SiteID=99
here is a screenie of it :P
http://img266.imageshack.us/img266/3549/tsklstei7.jpg
ps. to run the script, you must run this command first:
Set-ExecutionPolicy unrestricted
PHP:
$strComputer = "." # this is the config of wich computer (incase you want to use it against a server or something, you use the name(eg. //server))
$count = 0 # reset the counter, incase $count is already set by another script, or it's a re-run
$crits = 0 # reset the critical counter for same reasons
$colItems = get-wmiobject -class "Win32_Process" -namespace "root\CIMV2" `
-computername $strComputer | write-output
foreach ($objItem in $colItems) {
$objItem.WorkingSetSize = $objItem.WorkingSetSize / 1024
if ($objItem.WorkingSetSize -gt 25600) { # if the prosess uses more than 25600K of memory, highlight it with red color
write-host $objItem.Name, $objItem.WorkingSetSize -foregroundcolor "red" -backgroundcolor "black"
$crits++} # increment $crit
else {write-host $objItem.Name, $objItem.WorkingSetSize -backgroundcolor "black" -foregroundcolor "yellow"} # else output the prosess with yellow text
$count++ # increment the counter
}
write-host $count " prosesses running " $crits " are using more than 25 MB memory" -backgroundcolor "black" -foregroundcolor "green"
to test the code, you can go here:
https://connect.microsoft.com/site/s...aspx?SiteID=99
here is a screenie of it :P
http://img266.imageshack.us/img266/3549/tsklstei7.jpg
ps. to run the script, you must run this command first:
Set-ExecutionPolicy unrestricted