NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Windows PowerShell script

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
1719 unique views    
LinkBack Thread Tools
Old 10-12-2007, 08:34 AM THREAD STARTER               #1 (permalink)
Romance Of Love
Guest
Posts: n/a
 



Thumbs up 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 # reset the counter, incase $count is already set by another script, or it's a re-run
$crits # 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
 
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 07:14 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger