Windows PowerShell script

NamecheapNamecheap
Watch
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:


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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back