::::::::: PowerShell :::::::::
Saturday, January 07, 2006
  [TechNet] Do Scripters Dream of Magenta-Colored Text?
I was going over one of the highlighted Microsoft TechNet MSH Scripting article
Do Scripters Dream of Magenta-Colored Text?


The highlighted article talks about how to "Display Output in Color Using the Microsoft Shell". The gist of the whole discussion was about "-foreground" flag of "write-host" cmdlet(pronounced as Commandlet) which would let the scripter to decide which color(any of System.ConsoleColor retrievable through "MSH>$host.ui.rawui.foregroundcolor | gm -static")

The script seems to be from the guys who has written many VBScript tech scripts because the author has used WMI Class called "Win32_Process" which holds current process information of local or remote machine. I had a feeling that the author had no idea about "get-process".

Anyways, the following is the Scripting Guy's solution for displaying current process information in "Magenta" color.

$strComputer = "." 

$colItems = get-wmiobject -class "Win32_Process" -namespace "root\CIMV2" `
-computername $strComputer | write-object

foreach ($objItem in $colItems) {
write-host $objItem.Name, $objItem.WorkingSetSize -foregroundcolor "magenta"
}

The following is the shorter version using "get-process"

MSH>get-process | foreach { write-host $_.name, $_.WorkingSet -foregroundcolor "magenta" }

Woah, wasn't that much shorter and easier to write and read?
Anyways, one draw back of the latter approach is that it does not display "System Idle Process"... But not like anyone cares about that none process... :)

Tags:
 
Comments:
Yep, the guys should think a bit more "Monad-ish"

Now look at this MSH example on the Site :

http://www.microsoft.com/technet/scriptcenter/scripts/msh/hardware/basic/hwbams01.mspx

I would do this :

(get-wmiobject -class "Win32_ComputerSystem").get_properties() | ft name,value

gr /\/\o\/\/
 
Gosh.. that was the kind of word i was looking for "Monad-ish"... :) Thanks for the tips there /\/\o\/\/ :)
 
Post a Comment

Links to this post:

Create a Link



<< Home
Let's get lazy with PowerShell!

Name:
Location: Flushing, NY, United States

Experimenting with a different format of blogs...

Links
ARCHIVES
10/01/2005 - 11/01/2005 / 11/01/2005 - 12/01/2005 / 12/01/2005 - 01/01/2006 / 01/01/2006 - 02/01/2006 / 02/01/2006 - 03/01/2006 / 03/01/2006 - 04/01/2006 / 04/01/2006 - 05/01/2006 / 05/01/2006 - 06/01/2006 / 06/01/2006 - 07/01/2006 / 07/01/2006 - 08/01/2006 / 08/01/2006 - 09/01/2006 / 10/01/2006 - 11/01/2006 / 11/01/2006 - 12/01/2006 /


Powered by Blogger