{"id":85989,"date":"2015-11-09T07:09:47","date_gmt":"2015-11-09T15:09:47","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/scripting\/?p=85989"},"modified":"2019-06-11T07:32:57","modified_gmt":"2019-06-11T15:32:57","slug":"change-display-output-colors-in-powershell-ise-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/change-display-output-colors-in-powershell-ise-2\/","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=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/5282.2.png\"><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/5282.2.png\" alt=\"Image of Message\" width=\"876\" height=\"272\" class=\"aligncenter size-full wp-image-85991\" srcset=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/5282.2.png 876w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/5282.2-300x93.png 300w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/5282.2-768x238.png 768w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/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;\">&quot;The console color is now $_&quot;<\/p>\n<p style=\"margin-left:30px;\">Start-Sleep 1}<\/p>\n<p style=\"margin-left:30px;\">&quot;Now setting it back to default &#8230;&quot;<\/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=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/hsg-11-9-15-01.png\"><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/hsg-11-9-15-01.png\" alt=\"Image of Command Output\" width=\"1359\" height=\"938\" class=\"aligncenter size-full wp-image-85993\" srcset=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/hsg-11-9-15-01.png 1359w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/hsg-11-9-15-01-300x207.png 300w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/hsg-11-9-15-01-768x530.png 768w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2015\/11\/hsg-11-9-15-01-1024x707.png 1024w\" sizes=\"(max-width: 1359px) 100vw, 1359px\" \/><\/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>\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":[],"class_list":["post-85989","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting"],"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\/85989","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=85989"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/85989\/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=85989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=85989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=85989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}