0

Is there any way to retain the Powershell command coloring scheme after execution of the command in the Console Pane.

enter image description here

And is there a way to color the output column-headers separately.

None of the themes I browsed or could find online achieve this.

Ayan Mullick
  • 67
  • 2
  • 11
  • 38

2 Answers2

1

Try the following:

Get-Disk | Select -property * | ft -AutoSize -Wrap | Out-String -stream | %{if($_ | Select-String 'Style' -NotMatch){Write-Host $_ -f Yellow}else{Write-Host $_}}

This passes your output to a string. The -stream operator makes each line into a separate string, and you then check each string for something in your header ('Style'). If it checks, the string gets written out with the color formatting.

uruloki
  • 23
  • 5
  • Expanding on that idea, in your ForEach loop you could use a `Switch($_)` parser to get things more granular and output more color coding depending on the situation. – TheMadTechnician Mar 24 '14 at 22:33
  • @uruloki Isn't there anything I could do with the Powershell Theme ? – Ayan Mullick Mar 25 '14 at 00:22
  • You can use some of the various prompt functions from around the web/Stackoverflow to format it at all times. Try http://winterdom.com/2008/08/mypowershellprompt for a good start. – uruloki Mar 25 '14 at 15:01
  • @uruloki Yes, But how do I retain the coloring of **the cmdlet** after the cmdlet is executed........ – Ayan Mullick Mar 26 '14 at 10:53
  • Sorry, I am not understanding that question: Do you want the text that you type into the Powershell command line to be context sensitive as well? The code I provided will color all of the output for the cmdlet, but not change your cursor color. Please add the cmdlet code to the original question so we can see where your coloring is coming from. – uruloki Mar 27 '14 at 20:08
  • @AyanMullick Please ref the question above, I'd love to help! – uruloki Mar 28 '14 at 17:46
  • @uruloki After execution of any cmdlet, the cmdlet looses its coloring scheme as I showed in the picture above and in any Powershell theme. I want the coloring of the **CMDLET** to stay as it was when I was typing it; even after execution. I got what you wrote about coloring the output and Thanks for that. But I also need to retain the color of the **CMDLET** – Ayan Mullick Mar 29 '14 at 18:53
  • @AyanMullick As I understand the question, you want the command line input to remain green. I think something in your Get-Disk function is coloring the line so please provide the code in Get-Disk as I do not have that cmdlet. An alternative is to use the prompt function to color your prompt regardless of what a cmdlet does. – uruloki Mar 31 '14 at 18:32
  • @uruloki I don't want the command line input to remain green. I want it to retain it's coloring scheme. In a powershell theme you can configure the `command`,`parameter`,`argument` etc to have different colors. But those colors go away after the command has executed. I want the command to retain it's color after it executes. – Ayan Mullick Mar 31 '14 at 18:54
  • @AyanMullick Sorry, I do not know how to do that. In fact, until your screenshot I did not know that you could make the command line context sensitive. How do you get it to start like that? – uruloki Mar 31 '14 at 21:45
  • @uruloki `Powershell ISE`-`Tools`-`Options`-`Colors and Fonts`-`Console Pane`-`Console Tokens`....and assign the color you like. – Ayan Mullick Mar 31 '14 at 22:26
  • @AyanMullick Ok! You are using the PS ISE v4, which I did not have until today. You can't keep the context coloring on the executed command since PS is no longer parsing it. It's part of the history at that point. The live prompt will still have the right context coloring though, so you can use the up-arrow to see it colored or copy into the script window of the ISE to see it colored as well. – uruloki Apr 01 '14 at 19:02
  • @uruloki That is the question; how do I retain or freeze the coloring scheme :) – Ayan Mullick Apr 01 '14 at 19:34
  • @AyanMullick Why do you want to keep that? The live prompt is still colored correctly. – uruloki Apr 01 '14 at 19:46
  • @uruloki Sometimes I have to type a followup command to the previous command. It makes it easier to refer the previous command if the coloring scheme is retained. – Ayan Mullick Apr 01 '14 at 23:15
  • @AyanMullick I understand, from what I can find in the documentation that is not possible. – uruloki Apr 02 '14 at 22:02
0

The Output Colorizer VSC extension does it for the Output stream. I wish it could colorize the terminal output too. https://marketplace.visualstudio.com/items?itemName=IBM.output-colorizer

@uruloki

Ayan Mullick
  • 67
  • 2
  • 11
  • 38