Re: Colorize Get-Childitem Output

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"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


.



Relevant Pages

  • Colorize Get-Childitem Output
    ... 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 ... write-host command affects an object that is passed to it and/or point ...
    (microsoft.public.windows.server.scripting)
  • Re: Open with... Problems
    ... associate or re-associate your app with the particular file extension. ... can the below command (FileName ... I have a vb executable which opens text files to load the form. ... 'It can get pretty rough at break time, ...
    (comp.lang.basic.visual.misc)
  • Re: Whats going on!?!?
    ... Displays or modifies file extension associations ... fileType Specifies the file type to associate with the file extension ... type and the command will delete the association for the file extension. ... Type FTYPE without parameters to display the current file types that ...
    (comp.lang.ruby)
  • building a command string - separating commands and arguments
    ... fjg FirstTerm SecondTerm. ... Where I have a generic function that will search on any file extension ... echo Command: $ ... Another tack I have tried is to do the general find first, execute ...
    (comp.unix.shell)
  • Re: Creating a new file extension for application
    ... params = Command$() ... "Manrique Murillo" wrote in message ... i've made my application and create a new file extension. ... how do i pass command-line or parameters to MyApp, ...
    (microsoft.public.vb.winapi)