[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:
msh Monad