10-12-2007, 08:34 AM
| THREAD STARTER
#1 (permalink)
|
| Guest | Windows PowerShell script recently got my hands on the Windows PowerShell RC2 release, and darn, i'm impressed.Made a simple tasklist script: PHP Code: $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
????: NamePros.com http://www.namepros.com/code/384000-windows-powershell-script.html $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
????: NamePros.com http://www.namepros.com/showthread.php?t=384000 }
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 http://img266.imageshack.us/img266/3549/tsklstei7.jpg
ps. to run the script, you must run this command first:
Set-ExecutionPolicy unrestricted |
|
| |