{"id":1069,"date":"2011-01-21T09:14:06","date_gmt":"2011-01-21T14:14:06","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1069"},"modified":"2011-03-28T08:25:39","modified_gmt":"2011-03-28T12:25:39","slug":"friday-fun-out-rainbow","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/","title":{"rendered":"Friday Fun Out-Rainbow"},"content":{"rendered":"<p>For my readers who are just discovering my Friday posts, let me remind you that these are not necessarily practical, production worthy PowerShell scripts and functions. They are meant to be fun, yet educational. For example, in today's Friday Fun I have a function that takes string input and writes colored output to the console. So while you may not need the function itself, you might learn something about writing advanced functions, arrays, Write Host and  more. So today is all about rainbows, unicorns and puppies.<!--more--><br \/>\nFirst off, tt is important to remember that the PowerShell <em>host <\/em>is not the same as the PowerShell <em>pipeline<\/em>. The host is the application that is running PowerShell. It might be the PowerShell console you are used to using with the blue background, PowerShell.exe. Or it might be the Integrated Script Editor. Or a hosted application like <a href=\"http:\/\/www.primaltools.com\" target=\"_blank\">SAPIEN's PrimalScript<\/a>. The <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113426\" target=\"_blank\">Write-Host<\/a> cmdlet writes directly to the host and not the pipeline, ie no objects. This is critical because you can only work with objects. This is why you can't save Write-Host output to a text file: it was written to the host and not the pipeline.<\/p>\n<p>My function leverages Write-Host to write pretty colored text.<br \/>\n[cc lang=\"PowerShell\"]<br \/>\nFunction Out-Rainbow {<\/p>\n<p><#\n   .Synopsis\n    Write rainbow colored output to the console.\n    .Description\n    This function takes string input and writes each word in a random color to the host.\n    The function works best with the PowerShell console.\n    .Parameter Message\n    The string of text to colorize.\n    .Parameter Background\n    Temporarily change the background color. The screen will be cleared. At the end of the\n    command the background color will be changed back and you will manually need to run\n    Clear-Host.\n    \n    Valid colors are:  \"Black\",\"DarkMagenta\",\"DarkRed\",\"DarkBlue\",\"DarkGreen\",\"DarkCyan\",\n    \"DarkYellow\",\"Red\",\"Blue\",\"Green\",\"Cyan\",\"Magenta\",\"Yellow\",\"DarkGray\",\"Gray\",\"White\"\n   .Example\n    PS C:\\>\"Take the first step in faith. You don't have to see the whole staircase,\",<br \/>\n\"just take the first step.\",<br \/>\n\"  --Martin Luther King, Jr.\" | out-Rainbow<\/p>\n<p>    .Example<br \/>\n    PS C:\\> (get-process w* | out-string).Split(\"`r\") | out-rainbow<\/p>\n<p>    You'll get better results by converting the output to a string and then splitting it so<br \/>\n    that each line is processed completely by the function.<br \/>\n   .Notes<br \/>\n    NAME: Out-Rainbow<br \/>\n    AUTHOR: Jeffery Hicks<br \/>\n    VERSION: 1.0<br \/>\n    LASTEDIT: 01\/21\/2011<\/p>\n<p>    Learn more with a copy of Windows PowerShell 2.0: TFM (SAPIEN Press 2010)<\/p>\n<p>   .Link<br \/>\n    Http:\/\/jdhitsolutions.com\/blog<\/p>\n<p>    .Link<br \/>\n    Write-Host<br \/>\n    .Inputs<br \/>\n    Strings<\/p>\n<p>    .Outputs<br \/>\n    None<br \/>\n#><\/p>\n<p>Param (<br \/>\n  [Parameter(Position=0,Mandatory=$False,HelpMessage=\"Enter a message to display.\",<br \/>\n  ValueFromPipeline=$True)]<br \/>\n  [string[]]$Message,<\/p>\n<p>  [Parameter(Mandatory=$False,ValueFromPipeline=$False)]<br \/>\n  [ValidateSet(\"Black\",\"DarkMagenta\",\"DarkRed\",\"DarkBlue\",<br \/>\n    \"DarkGreen\",\"DarkCyan\",\"DarkYellow\",\"Red\",<br \/>\n    \"Blue\",\"Green\",\"Cyan\",\"Magenta\",\"Yellow\",<br \/>\n    \"DarkGray\",\"Gray\",\"White\")]<br \/>\n  [string]$Background=$Host.UI.RawUI.BackGroundColor<br \/>\n  )<\/p>\n<p>Begin<br \/>\n{<br \/>\n    #measure the $Message variable. A value of 0 means it was piped in<br \/>\n    #and a value greater than 0 means it as passed as a parameter<br \/>\n    #This has an affect on the processed output.<br \/>\n    if (($message | measure-object).Count -eq 0)<br \/>\n    {<br \/>\n        Write-Verbose \"Pipelined input\"<br \/>\n        $Pipelined=$True<br \/>\n    }<\/p>\n<p>    #define the array of valid colors<br \/>\n    $AllColors=@(<br \/>\n    \"Black\",\"DarkMagenta\",\"DarkRed\",\"DarkBlue\",<br \/>\n    \"DarkGreen\",\"DarkCyan\",\"DarkYellow\",\"Red\",<br \/>\n    \"Blue\",\"Green\",\"Cyan\",\"Magenta\",\"Yellow\",<br \/>\n    \"DarkGray\",\"Gray\",\"White\"<br \/>\n    )<\/p>\n<p>    Write-Verbose \"Omitting $($host.ui.RawUI.Backgroundcolor) from color array\"<\/p>\n<p>    #filter out the current background color<br \/>\n    $colors=$AllColors | Where {$_ -ne $host.ui.RawUI.Backgroundcolor}<\/p>\n<p>    #Check if -Background was called and if the value is different than the current<br \/>\n    #background.<\/p>\n<p>    if ($Background -ne $Host.UI.RawUI.BackgroundColor)<br \/>\n    {<br \/>\n        #save current color<br \/>\n        $SavedBGColor=$Host.UI.RawUI.BackgroundColor<br \/>\n        #set background color<br \/>\n        $Host.UI.RawUI.BackgroundColor=$Background<br \/>\n        #need to clear the host for this to work properly<br \/>\n        Clear-Host<br \/>\n        Write-Verbose \"Changed background color ro $Background\"<br \/>\n    }<br \/>\n} #close Begin<\/p>\n<p>Process<br \/>\n{<br \/>\n    ForEach ($m in $Message) {<br \/>\n        Write-Verbose \"Splitting message $m\"<br \/>\n        #split the line into a word array<br \/>\n        $arr=$m.Split()<br \/>\n        Write-Verbose \"Now have $($arr.count) words\"<\/p>\n<p>        for ($i=0;$i -lt $arr.count;$i++)<br \/>\n        {<br \/>\n            #write each word followed by a space. Don't insert a new line<br \/>\n            Write-Host \"$($arr[$i]) \" -foregroundcolor $colors[(Get-Random -Min 0 -max ($colors.count-1))] -NoNewline<br \/>\n        } #for<\/p>\n<p>         if (-Not $Pipelined)<br \/>\n         {<br \/>\n            #if not pipelined input then add a carriage retrun<br \/>\n            Write-host `r<br \/>\n          }<br \/>\n    } #foreach<\/p>\n<p>    #add a carriage return after each processed object<br \/>\n    write-host `r<\/p>\n<p>    } #close Process<\/p>\n<p>End<br \/>\n{<br \/>\n    #change the background color back if there is a saved color<br \/>\n    if ($SavedBGColor)<br \/>\n    {<br \/>\n        Write-Verbose \"Returning background color to $SavedBGColor\"<br \/>\n        $host.UI.RawUI.BackgroundColor=$SavedBGColor<br \/>\n    }<br \/>\n    #write a carriage return for visual clarity<br \/>\n   Write-Host `r<br \/>\n   Write-Verbose \"We've reached the end of the rainbow\"<br \/>\n} #close End<\/p>\n<p>} #end function<br \/>\n[\/cc]<\/p>\n<p>Write-Host has some useful parameters like -Foregroundcolor which let you specify a text color. However, not every host supports it. But for our purposes, assuming you are using the standard PowerShell console we're good. My Out-Rainbow function takes a message string, or a collection of them, then splits each line into it's component words.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nForEach ($m in $Message) {<br \/>\n        Write-Verbose \"Splitting message $m\"<br \/>\n        #split the line into a word array<br \/>\n        $arr=$m.Split()<br \/>\n        Write-Verbose \"Now have $($arr.count) words\"<br \/>\n[\/cc]<br \/>\nThe function then goes through each word in the array, $arr, and writes it to the host with a color randomly selected from an array.<br \/>\n[cc lang=\"PowerShell\"]<br \/>\n for ($i=0;$i -lt $arr.count;$i++)<br \/>\n        {<br \/>\n            #write each word followed by a space. Don't insert a new line<br \/>\n            Write-Host \"$($arr[$i]) \" -foregroundcolor $colors[(Get-Random -Min 0 -max ($colors.count-1))] -NoNewline<br \/>\n        } #for<br \/>\n[\/cc]<\/p>\n<p>The function omits the current background color from the array so you don't have any \"invisible\" words. You can also use the -Background parameter to temporarily change it. I find Black or White work best. The function will restore your original color, but you'll want to run CLS afterwards.<\/p>\n<p>Here's an example.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1-1024x412.png\" alt=\"\" title=\"out-rainbow-1\" width=\"640\" height=\"257\" class=\"aligncenter size-large wp-image-1071\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1-1024x412.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1-300x120.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1.png 1256w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>The function automatically converts objects to strings, so sometimes you can do this:<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-2-1024x412.png\" alt=\"\" title=\"out-rainbow-2\" width=\"640\" height=\"257\" class=\"aligncenter size-large wp-image-1072\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-2-1024x412.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-2-300x120.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-2.png 1256w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>To fully convert cmdlet output takes a little sleight of hand. You need to convert it all to a string then split it at each line return. I could probably include code in the function to handle this automatically but that will have to wait for a future version.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-3-1024x412.png\" alt=\"\" title=\"out-rainbow-3\" width=\"640\" height=\"257\" class=\"aligncenter size-large wp-image-1073\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-3-1024x412.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-3-300x120.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-3.png 1256w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow.txt'>Out-Rainbow.ps1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my readers who are just discovering my Friday posts, let me remind you that these are not necessarily practical, production worthy PowerShell scripts and functions. They are meant to be fun, yet educational. For example, in today&#8217;s Friday Fun I have a function that takes string input and writes colored output to the console&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[271,4],"tags":[145,32,534,101],"class_list":["post-1069","post","type-post","status-publish","format-standard","hentry","category-friday-fun","category-powershell","tag-array","tag-functions","tag-powershell","tag-write-host"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun Out-Rainbow &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun Out-Rainbow &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"For my readers who are just discovering my Friday posts, let me remind you that these are not necessarily practical, production worthy PowerShell scripts and functions. They are meant to be fun, yet educational. For example, in today&#039;s Friday Fun I have a function that takes string input and writes colored output to the console....\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-01-21T14:14:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2011-03-28T12:25:39+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1-1024x412.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun Out-Rainbow\",\"datePublished\":\"2011-01-21T14:14:06+00:00\",\"dateModified\":\"2011-03-28T12:25:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/\"},\"wordCount\":889,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/01\\\/out-rainbow-1-1024x412.png\",\"keywords\":[\"Array\",\"functions\",\"PowerShell\",\"Write-Host\"],\"articleSection\":[\"Friday Fun\",\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/\",\"name\":\"Friday Fun Out-Rainbow &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/01\\\/out-rainbow-1-1024x412.png\",\"datePublished\":\"2011-01-21T14:14:06+00:00\",\"dateModified\":\"2011-03-28T12:25:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/01\\\/out-rainbow-1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/01\\\/out-rainbow-1.png\",\"width\":\"1256\",\"height\":\"506\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1069\\\/friday-fun-out-rainbow\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Friday Fun\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/friday-fun\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun Out-Rainbow\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Friday Fun Out-Rainbow &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun Out-Rainbow &#8226; The Lonely Administrator","og_description":"For my readers who are just discovering my Friday posts, let me remind you that these are not necessarily practical, production worthy PowerShell scripts and functions. They are meant to be fun, yet educational. For example, in today's Friday Fun I have a function that takes string input and writes colored output to the console....","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-01-21T14:14:06+00:00","article_modified_time":"2011-03-28T12:25:39+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1-1024x412.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun Out-Rainbow","datePublished":"2011-01-21T14:14:06+00:00","dateModified":"2011-03-28T12:25:39+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/"},"wordCount":889,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1-1024x412.png","keywords":["Array","functions","PowerShell","Write-Host"],"articleSection":["Friday Fun","PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/","name":"Friday Fun Out-Rainbow &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1-1024x412.png","datePublished":"2011-01-21T14:14:06+00:00","dateModified":"2011-03-28T12:25:39+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/01\/out-rainbow-1.png","width":"1256","height":"506"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1069\/friday-fun-out-rainbow\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Friday Fun","item":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},{"@type":"ListItem","position":2,"name":"Friday Fun Out-Rainbow"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1307,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1307\/friday-fun-powershell-pep-talk\/","url_meta":{"origin":1069,"position":0},"title":"Friday Fun PowerShell Pep Talk","author":"Jeffery Hicks","date":"April 1, 2011","format":false,"excerpt":"Today's Friday Fun is meant to help get you excited about the upcoming Scripting Games. I want to add a little pep to your PowerShell prompt. Perhaps it will even keep you motivated. What I have for you today are variety of prompt functions. Consider them variations on a theme.\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"PowerShell Pep Talk","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/04\/color-pep-prompt-300x144.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6240,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6240\/friday-fun-with-timely-powershell-prompts\/","url_meta":{"origin":1069,"position":1},"title":"Friday Fun with Timely PowerShell Prompts","author":"Jeffery Hicks","date":"November 30, 2018","format":false,"excerpt":"If PowerShell is a part of your daily routine, you most likely have a console window open all day. In addition to using PowerShell to get stuff done, you can use PowerShell to keep you on track. I've written before and talked about how I use PowerShell to manage my\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":867,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/867\/friday-fun-music-of-the-shell\/","url_meta":{"origin":1069,"position":2},"title":"Friday Fun: Music of the Shell","author":"Jeffery Hicks","date":"August 27, 2010","format":false,"excerpt":"We made it to the end of the week, and I don't know about you but I have my head buried in PowerShell work. But you know what they say about all work and no fun...so I figured I'd take a break from serious PowerShell and do something a little\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5958,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5958\/friday-fun-perk-up-your-powershell-prompt\/","url_meta":{"origin":1069,"position":3},"title":"Friday Fun: Perk Up Your PowerShell Prompt","author":"Jeffery Hicks","date":"April 6, 2018","format":false,"excerpt":"I haven't written a Friday Fun post in quite a while. Often these posts don't have much practical value but hopefully illustrate a concept or technique. Although what I have today is something you could use immediately. I have a version of a PowerShell prompt function that will color code\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/04\/pslocationprompt-2_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/04\/pslocationprompt-2_thumb.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/04\/pslocationprompt-2_thumb.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":9187,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9187\/friday-fun-powershell-scripting-with-chatgpt\/","url_meta":{"origin":1069,"position":4},"title":"Friday Fun: PowerShell Scripting with ChatGPT","author":"Jeffery Hicks","date":"December 16, 2022","format":false,"excerpt":"I have been trying out the latest AI, ChatGPT. I've asked it silly questions. As well as the really important questions. But what I find most fascinating is using ChatGPT to write PowerShell code. I gave the AI this instruction: \"Write a PowerShell function that will display \"Hello, World\" in\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/12\/woodchuck.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/12\/woodchuck.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/12\/woodchuck.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/12\/woodchuck.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/12\/woodchuck.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/12\/woodchuck.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":3912,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3912\/friday-fun-a-random-powershell-console\/","url_meta":{"origin":1069,"position":5},"title":"Friday Fun: A Random PowerShell Console","author":"Jeffery Hicks","date":"July 11, 2014","format":false,"excerpt":"This week I thought we'd have a little fun with the PowerShell console and maybe pick up a few scripting techniques along the way. Today I have a function that changes the foreground and background colors of your PowerShell console to random values. But because you might want to go\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"crayons","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/11\/crayons-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1069"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1069\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}