{"id":5079,"date":"2012-08-25T11:59:00","date_gmt":"2012-08-25T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/08\/25\/powertip-use-powershell-to-create-color-output-from-commands\/"},"modified":"2012-08-25T11:59:00","modified_gmt":"2012-08-25T11:59:00","slug":"powertip-use-powershell-to-create-color-output-from-commands","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-use-powershell-to-create-color-output-from-commands\/","title":{"rendered":"PowerTip: Use PowerShell to Create Color Output from Commands"},"content":{"rendered":"<p><b>Summary<\/b>: Learn to use the&nbsp;<b>Write-Host<\/b>&nbsp;PowerShell cmdlet to create color output from commands.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Someone told me the&nbsp;<b>Write-Host<\/b>&nbsp;cmdlet could create color output. Can you give me some samples of acceptable syntax?<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/><\/p>\n<p style=\"padding-left: 60px\"><strong>a.<\/strong> Write-Host -ForegroundColor 12 &#8220;hi&#8221;<\/p>\n<p style=\"padding-left: 60px\"><strong>b<\/strong>. Write-Host -ForegroundColor 12 &#8220;hi&#8221; -BackgroundColor white<\/p>\n<p style=\"padding-left: 60px\"><strong>c.<\/strong> Write-Host -ForegroundColor blue -BackgroundColor white<\/p>\n<p style=\"padding-left: 60px\"><strong>d.<\/strong> Write-Host -ForegroundColor 2 hi<\/p>\n<p style=\"padding-left: 60px\"><strong>e.<\/strong> Write-Host -backgroundcolor 2 hi<\/p>\n<p style=\"padding-left: 60px\"><strong>f.<\/strong> Write-Host -backgroundcolor (&#8220;{0:X}&#8221; -f 2) hi<\/p>\n<p style=\"padding-left: 60px\">&nbsp; &nbsp; &nbsp;for($i=0 ; $i -le 15 ; $i++) { write-host -foregroundcolor $i &#8220;hi&#8221; }<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\" border=\"0\" alt=\"\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn to use the&nbsp;Write-Host&nbsp;PowerShell cmdlet to create color output from commands. &nbsp;Someone told me the&nbsp;Write-Host&nbsp;cmdlet could create color output. Can you give me some samples of acceptable syntax? a. Write-Host -ForegroundColor 12 &#8220;hi&#8221; b. Write-Host -ForegroundColor 12 &#8220;hi&#8221; -BackgroundColor white c. Write-Host -ForegroundColor blue -BackgroundColor white d. Write-Host -ForegroundColor 2 hi e. Write-Host -backgroundcolor [&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":[356,3,45],"class_list":["post-5079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn to use the&nbsp;Write-Host&nbsp;PowerShell cmdlet to create color output from commands. &nbsp;Someone told me the&nbsp;Write-Host&nbsp;cmdlet could create color output. Can you give me some samples of acceptable syntax? a. Write-Host -ForegroundColor 12 &#8220;hi&#8221; b. Write-Host -ForegroundColor 12 &#8220;hi&#8221; -BackgroundColor white c. Write-Host -ForegroundColor blue -BackgroundColor white d. Write-Host -ForegroundColor 2 hi e. Write-Host -backgroundcolor [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5079","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=5079"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5079\/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=5079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=5079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=5079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}