This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
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.
# LS.MSH
# 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"}
$item
}
$host.ui.rawui.foregroundColor = $origFg
}
Tags : Monad msh