{"id":74391,"date":"2015-11-09T00:01:00","date_gmt":"2015-11-09T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/11\/09\/change-display-output-colors-in-powershell-ise\/"},"modified":"2019-02-18T09:34:36","modified_gmt":"2019-02-18T16:34:36","slug":"change-display-output-colors-in-powershell-ise","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/change-display-output-colors-in-powershell-ise\/","title":{"rendered":"Change Display Output Colors in PowerShell ISE"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Ed Wilson, Microsoft Scripting Guy, talks about changing the output console colors in the Windows PowerShell ISE.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the things I like about using the <b>Write-Host<\/b> cmdlet is that I can change the color of a line that writes to the Windows PowerShell console. But, what if I want to change the entire output console so that the output is really obvious? I can also do that on the fly by using the <b>$host<\/b> object. As shown here, the <b>$host<\/b> object returns a number of properties, and it contains a number of other objects:<\/p>\n<p style=\"margin-left:30px\">PS C:\\Users\\mredw&gt; $host<\/p>\n<p style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Windows PowerShell ISE Host<\/p>\n<p style=\"margin-left:30px\">Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 5.0.10240.16384<\/p>\n<p style=\"margin-left:30px\">InstanceId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 92ba5361-53ee-4217-82d2-bf54710efcbe<\/p>\n<p style=\"margin-left:30px\">UI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : System.Management.Automation.Internal.Host.InternalHostUserInterf<span style=\"font-size:12px\">ace<\/span><\/p>\n<p style=\"margin-left:30px\">CurrentCulture&nbsp;&nbsp; : en-US<\/p>\n<p style=\"margin-left:30px\">CurrentUICulture : en-US<\/p>\n<p style=\"margin-left:30px\">PrivateData&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.PowerShell.Host.ISE.ISEOptions<\/p>\n<p style=\"margin-left:30px\">DebuggerEnabled&nbsp; : True<\/p>\n<p style=\"margin-left:30px\">IsRunspacePushed : False<\/p>\n<p style=\"margin-left:30px\">Runspace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : System.Management.Automation.Runspaces.LocalRunspace<\/p>\n<p>The embedded object I want is the host interface object. It is in the UI property. When I access it, I see that there is a <b>RawUI<\/b> property that contains another object:<\/p>\n<p style=\"margin-left:30px\">PS C:\\Users\\mredw&gt; $host.UI<\/p>\n<p style=\"margin-left:30px\">RawUI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">System.Management.Automation.Internal.Host.InternalHostRawUserInterface<span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n<p>The <b>RawUI<\/b> object is really cool and it contains a number of interesting properties:<\/p>\n<p style=\"margin-left:30px\">PS C:\\Users\\mredw&gt; $host.UI.RawUI<\/p>\n<p style=\"margin-left:30px\"><span style=\"font-size:12px\">ForegroundColor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : White<\/span><\/p>\n<p style=\"margin-left:30px\">BackgroundColor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : -1<\/p>\n<p style=\"margin-left:30px\">CursorPosition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0,0<\/p>\n<p style=\"margin-left:30px\">WindowPosition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">CursorSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">BufferSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 85,0<\/p>\n<p style=\"margin-left:30px\">WindowSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">MaxWindowSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">MaxPhysicalWindowSize :<\/p>\n<p style=\"margin-left:30px\">KeyAvailable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">WindowTitle&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: Windows PowerShell ISE<\/p>\n<p>If I want to know what the possible enumeration values are for <b>ForegroundColor<\/b>, I can give it a bogus number and look at the returned error message:<\/p>\n<p><a href=\"\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-76-18\/5282.2.PNG\"><img decoding=\"async\" src=\"\/resized-image.ashx\/__size\/550x0\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-76-18\/5282.2.PNG\" alt=\"Image of message\" title=\"Image of message\"><\/a><\/p>\n<p>It tells me that the enumeration is <b>System.ConsoleColor<\/b>, and that the possible values are: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, and White.<\/p>\n<p>If I count them, that is 16 possible values, and I bet I can go from 0 to 15.<\/p>\n<p>Armed with this information, I decide to write a little script that will change the foreground color to a different value every second. I create an array of numbers from 0 to 15 by using the range operator:<\/p>\n<p style=\"margin-left:30px\">0..15.<\/p>\n<p>Then I read the current foreground color and store it in a variable:<\/p>\n<p style=\"margin-left:30px\">$color = $Host.UI.RawUI.ForegroundColor<\/p>\n<p>Now I use the <b>Foreach-Object<\/b> cmdlet, pipe the numbers across the pipeline, and assign new <b>ForegroundColor<\/b> values:<\/p>\n<p style=\"margin-left:30px\">Foreach-Object {<\/p>\n<p style=\"margin-left:30px\">$Host.UI.RawUI.ForegroundColor = $_<\/p>\n<p>I print a message that says what the foreground color is, and then I sleep for a second. I continue to loop through the numbers. When I am done, I revert back to the original color. The complete script is shown here:<\/p>\n<p style=\"margin-left:30px\">Clear-Host<\/p>\n<p style=\"margin-left:30px\">$color = $Host.UI.RawUI.ForegroundColor<\/p>\n<p style=\"margin-left:30px\">0..15 |<\/p>\n<p style=\"margin-left:30px\">Foreach-Object {<\/p>\n<p style=\"margin-left:30px\">$Host.UI.RawUI.ForegroundColor = $_<\/p>\n<p style=\"margin-left:30px\">&#8220;The console color is now $_&#8221;<\/p>\n<p style=\"margin-left:30px\">Start-Sleep 1}<\/p>\n<p style=\"margin-left:30px\">&#8220;Now setting it back to default &#8230;&#8221;<\/p>\n<p style=\"margin-left:30px\">$Host.UI.RawUI.ForegroundColor = $color&nbsp;<\/p>\n<p>When I run it, the following output appears:<\/p>\n<p><a href=\"\/cfs-file.ashx\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-76-18\/hsg_2D00_11_2D00_9_2D00_15_2D00_01.png\"><img decoding=\"async\" src=\"\/resized-image.ashx\/__size\/550x0\/__key\/communityserver-blogs-components-weblogfiles\/00-00-00-76-18\/hsg_2D00_11_2D00_9_2D00_15_2D00_01.png\" alt=\"Image of command output\" title=\"Image of command output\"><\/a><\/p>\n<p>That is all there is to using Windows PowerShell to change the ISE output console colors.&nbsp; Join me tomorrow when I will talk about more cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about changing the output console colors in the Windows PowerShell ISE. Microsoft Scripting Guy, Ed Wilson, is here. One of the things I like about using the Write-Host cmdlet is that I can change the color of a line that writes to the Windows PowerShell console. But, what [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[553,3,45],"class_list":["post-74391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-ise","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about changing the output console colors in the Windows PowerShell ISE. Microsoft Scripting Guy, Ed Wilson, is here. One of the things I like about using the Write-Host cmdlet is that I can change the color of a line that writes to the Windows PowerShell console. But, what [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/74391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=74391"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/74391\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=74391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=74391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=74391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}