/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" MSH GUI Viewer for Dataset Example "," More DataTables and joining them in Monad "," MSH Get-MSDN Function "," Getting and Working With SQL Server data in Monad "," MSH Cluster Watcher script "," Monad NewYears Clock "," Using ADO to get data from Excel to Dataset in Monad. "," Monad Really Does Rock "," Passing (not so) mandatory Parameters to WMI metho... "," Saving a WMI instance to a XML-file from MSH "," ")

Monday, January 02, 2006


Colorized MSH LS replacement.

The following script will color the output of LS.

It's sets the ConsoleColor depending on extension.

it does not use Out-Host -ForeColor for this for 2 reasons.

1 it will only be outputed to the console, we can not redirect it.
2 It will be translated to text so we can not pipeline the output anymore.

so the output stays an object, and is still usable as there is no output the consolecolorchanges have no effect. (try ls | out-string)

For more info see the following thread on
microsoft.public.windows.server.scripting about this.

As this is the first post of 2006, Happy New Year.

gr /\/\o\/\/

PS (edit) you need this to overrule LS :
set-alias ls ll -force -option allscope

*Edit* added Directory color.

# Colorized LS function replacement 
# /\/\o\/\/ 2006 
# http://mow001.blogspot.com 

function LL { param ($dir = "."
  $origFg = $host.ui.rawui.foregroundColor 
  foreach ($Item in (LS $dir))  
    Switch ($Item.Extension)  
      ".Exe" {$host.ui.rawui.foregroundColor = "Yellow"
      ".cmd" {$host.ui.rawui.foregroundColor = "Green"
      ".msh" {$host.ui.rawui.foregroundColor = "Red"
      ".vbs" {$host.ui.rawui.foregroundColor = "Red"
      Default {$host.ui.rawui.foregroundColor = $origFg} 
    if ($item.Mode.StartsWith("d")) {$host.ui.rawui.foregroundColor = "Blue"}
  $host.ui.rawui.foregroundColor = $origFg 

Tags :

Blogger Sung Meister
It is just funny to see how the script is evolving by itself in the usenet posts... :)

Maybe it might be the time to update your script a bit? :)
Blogger /\/\o\/\/
very interesting thread, also the way to the script before.

I also like the "how to delete folders containing strange character" thread

also the "[msh]Get-Acl not returning output" Thread, mentioned in next post.

as I said before I think the newsgroup is Great

B.t.w. as you might know I can only edit my posts in HTML mode so it's to difficult from me to update, but I did mention the tread.

But the 2 changes, for the ones still not interested in the tread ;-) :

$item.MshIsContainer = $true.

(provider independent, so the dircolor works also with other providers, ofcouse not the filecolors)

and your change to do the switch after the directory check what is more efficient.

gr /\/\o\/\/
Blogger /\/\o\/\/

as I post this comment the thread goes on with a GPS with XML coloring Sample.

by Jacques Barathon

gr /\/\o\/\/
Anonymous Anonymous
You could also differentiate between the attributes set: (like FileInfo does in Types.MshXml)

$catr = "";
if ( $this.Attributes -band 16 ) { $catr += "d" } else { $catr += "-" } ;
if ( $this.Attributes -band 32 ) { $catr += "a" } else { $catr += "-" } ;
if ( $this.Attributes -band 1 ) { $catr += "r" } else { $catr += "-" } ;
if ( $this.Attributes -band 2 ) { $catr += "h" } else { $catr += "-" } ;
if ( $this.Attributes -band 4 ) { $catr += "s" } else { $catr += "-" } ;
Blogger /\/\o\/\/
Nice idea,

it would not be handy to color only the atributes I think, but for useage as a parameter and then color it that way would be nice.

thanks, for the comment,
if I make an update I will add it.

gr /\/\o\/\/
Post a Comment

<< Home


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?