Re: Colorize Get-Childitem Output
- From: "Keith Hill" <r_keith_hill@xxxxxxxxxxxxxxxxxx>
- Date: Sun, 1 Jan 2006 15:31:55 -0700
"Tom G." <Tom.Glowacki@xxxxxxxxxxx> wrote in message news:1136152459.490015.156980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm working on a function that will colorize the get-childitem output based upon file extension, similar to what can be done with the ls command in Linux. However, the issue I'm running into is that after sending the get-childitem object down the pipe, I only get the file names or directory names returned rather than the full output from the get-childitem cmdlet. Among the variations I've tried include the following (no extension checking is being done):
1) get-childitem | foreach-object {write-host -ForegroundColor "yellow" $_} 2) write-host -ForegroundColor "yellow" $(get-childitem)
It seems that the write-host cmdlet is stripping the object of all properties except the name property. Can anyone explain how the write-host command affects an object that is passed to it and/or point me in the right direction as to how to get the full get-childitem output in color?
I ran into this same issue a few days ago. Try this:
function colorize {
$origFg = $host.ui.rawui.foregroundColor
write-host -ForegroundColor "Yellow" $(get-childitem)
$host.ui.rawui.foregroundColor = $origFg
}You could make this more robust by putting in a trap that always makes sure to reset the foreground color to $origFg.
--
Keith
.
- Follow-Ups:
- Re: Colorize Get-Childitem Output
- From: Tom G.
- Re: Colorize Get-Childitem Output
- References:
- Colorize Get-Childitem Output
- From: Tom G.
- Colorize Get-Childitem Output
- Prev by Date: Colorize Get-Childitem Output
- Next by Date: Re: Colorize Get-Childitem Output
- Previous by thread: Colorize Get-Childitem Output
- Next by thread: Re: Colorize Get-Childitem Output
- Index(es):
Relevant Pages
|