{"id":8871,"date":"2022-02-14T10:56:48","date_gmt":"2022-02-14T15:56:48","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8871"},"modified":"2022-02-14T10:56:52","modified_gmt":"2022-02-14T15:56:52","slug":"more-colorful-fun-with-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/","title":{"rendered":"More Colorful Fun with PowerShell"},"content":{"rendered":"\n<p>In <a href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8853\/friday-fun-painting-a-pretty-picture-with-powershell\/\" target=\"_blank\" rel=\"noreferrer noopener\">my last Friday Fun post,<\/a> I shared some PowerShell code for displaying [System.Drawing.Color] values from a console using ANSI escape sequences. After I published the article, I realized what I <em>really <\/em>wanted was a color palette display that wouldn't be affected by the console background. A Windows Presentation Foundation (WPF) form would do the trick. I could use the form to display a color sample. WPF is a handy technique for displaying information, and it doesn't have to involve complex XAML files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"start-simple\">Start Simple<\/h2>\n\n\n\n<p>I often create PowerShell scripts to generate WPF output that doesn't rely on XAML files. For simple displays, you can accomplish everything with PowerShell code. The first step in any WPF project is to add the required assembly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Add-Type -AssemblyName PresentationFramework<\/code><\/pre>\n\n\n\n<p>I first wrote some proof-of-concept code to display a single color. Eventually, I knew I wanted to display the entire color palette. Focusing on showing a single color would identify potential problems or gaps in my WPF knowledge, which I know there are plenty of.<\/p>\n\n\n\n<p>The first step is to define the window form.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$form = New-Object System.Windows.Window\n$form.Title = \"Color Sample\"\n$form.Height = 100\n$form.Width = 300\n$form.top = 200\n$form.left = 100\n$form.UseLayoutRounding = $True\n$form.WindowStartupLocation = \"CenterScreen\"<\/code><\/pre>\n\n\n\n<p>The property names should be self-explanatory. With WPF, the controls, such as buttons and textboxes, have to live inside a container, not to be confused with a Docker container. For simple WPF forms, I often use a Stack Panel.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$stack = New-Object System.Windows.Controls.StackPanel<\/code><\/pre>\n\n\n\n<p>I think of this as a series of shelves. Each control that I add to the stack is layered in order. My stack only needs a TextBox.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$TextBox = New-Object System.Windows.Controls.TextBox\n$TextBox.Width = 275\n$textbox.Height = 30\n$TextBox.HorizontalAlignment = \"Center\"\n$textbox.TextAlignment = \"center\"\n$textbox.VerticalContentAlignment = \"center\"\n$textbox.FontSize = 16<\/code><\/pre>\n\n\n\n<p>By the way, I realize you may not be familiar with all of a particular control's properties. No problem. You can use Get-Member.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$TextBox | Get-Member<\/code><\/pre>\n\n\n\n<p>I want to set the textbox background to the specified color and the textbox text to show the color name and RGB  values. Here's where I hit my first hurdle.<\/p>\n\n\n\n<p>The Background property is expecting an object type of [System.Windows.Media.Brush].<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.png\"><img loading=\"lazy\" decoding=\"async\" width=\"765\" height=\"213\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.png\" alt=\"TextBox Background property\" class=\"wp-image-8872\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.png 765w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background-300x84.png 300w\" sizes=\"auto, (max-width: 765px) 100vw, 765px\" \/><\/a><\/figure>\n\n\n\n<p>I intend to provide a name value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$color = \"cornsilk\"<\/code><\/pre>\n\n\n\n<p>I know I can get the [System.Drawing.Color] object from this value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$sdc = [System.Drawing.Color]::FromName($color)<\/code><\/pre>\n\n\n\n<p>But that is a different object type. After a little online research and learning more about WPF, I discovered the [System.Windows.Media.BrushConverter] class. I could use this to convert colors to the [System.Windows.Media.Brush] class. The converter has a ConvertFromString() method. The parameter is an HTML color string such as #FFF8DC I have the RGB values from [System.Drawing.Color]. How do I convert them to the HTML string?<\/p>\n\n\n\n<p>Once again, I learned something new. I have never paid any attention to HTML color codes. I knew how to use them but never considered how they were constructed. Here's an example of why I think it is essential to understand <em>why <\/em>PowerShell behaves and not merely regurgitate a command. I discovered that the HTML code is the RGB value converted to hex. That I can do.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/hex-poc.png\"><img loading=\"lazy\" decoding=\"async\" width=\"382\" height=\"160\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/hex-poc.png\" alt=\"converting Red value to hex\" class=\"wp-image-8873\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/hex-poc.png 382w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/hex-poc-300x126.png 300w\" sizes=\"auto, (max-width: 382px) 100vw, 382px\" \/><\/a><\/figure>\n\n\n\n<p>The format string is case-sensitive, so be sure to use X. The 2 indicates format to two places, which is important when formatting zero values. With this in mind, I can convert values and set the TextBox properties.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$htmlcode = \"#{0:X2}{1:X2}{2:X2}\" -f $sdc.r, $sdc.g, $sdc.b\n$textbox.background = [System.Windows.Media.BrushConverter]::new().ConvertFromString($htmlcode)\n$name = $sdc.Name\n$TextBox.Text = \"$name ($($sdc.R),$($sdc.G),$($sdc.B))\"<\/code><\/pre>\n\n\n\n<p>All that remains is to add the Textbox to the stack, add the stack to the form, and display the form.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$stack.AddChild($TextBox)\n$form.AddChild($stack)\n[void]$form.ShowDialog()<\/code><\/pre>\n\n\n\n<p>Be sure to use the ShowDialog() method and <strong><em>not <\/em><\/strong>Show(). The ShowDialog() method returns a Boolean value that I rarely need to see, so I cast the output to [Void]. Your PowerShell prompt will be blocked until you close the form.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/single-color-sample.png\"><img loading=\"lazy\" decoding=\"async\" width=\"286\" height=\"93\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/single-color-sample.png\" alt=\"\" class=\"wp-image-8874\"\/><\/a><\/figure>\n\n\n\n<p>I didn't add a button to the form. I click the X to close the window.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"show-singlecolor\">Show-SingleColor<\/h2>\n\n\n\n<p>I wrapped all of my code into a PowerShell function. Remember to include the Add-Type command in the script file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Show-SingleColor {\n    Param([string]$Color)\n\n    $form = New-Object System.Windows.Window\n    $form.Title = \"Color Sample\"\n    $form.Height = 100\n    $form.Width = 300\n    $form.top = 200\n    $form.left = 100\n    $form.UseLayoutRounding = $True\n    $form.WindowStartupLocation = \"CenterScreen\"\n\n    $stack = New-Object System.Windows.Controls.StackPanel\n\n    $TextBox = New-Object System.Windows.Controls.TextBox\n    $TextBox.Width = 275\n    $textbox.Height = 30\n    $TextBox.HorizontalAlignment = \"Center\"\n    $textbox.TextAlignment = \"center\"\n    $textbox.VerticalContentAlignment = \"center\"\n    $textbox.FontSize = 16\n    #The drawing color may need to be converted to a brush color\n    #convert color to html value\n    $sdc = [System.Drawing.Color]::FromName($color)\n    #get RGB values and convert to HTML\n    $htmlcode = \"#{0:X2}{1:X2}{2:X2}\" -f $sdc.r, $sdc.g, $sdc.b\n    $textbox.background = [System.Windows.Media.BrushConverter]::new().ConvertFromString($htmlcode)\n    $name = $sdc.Name\n    $TextBox.Text = \"$name ($($sdc.R),$($sdc.G),$($sdc.B))\"\n    $stack.AddChild($TextBox)\n    $form.AddChild($stack)\n    [void]$form.ShowDialog()\n}<\/code><\/pre>\n\n\n\n<p>This function is a handy tool when I only need to see a single color, which I may still want. The actual value of my code was serving as a testbed and laying the foundation for more complex WPF and PowerShell functions. I'll dive into those next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my last Friday Fun post, I shared some PowerShell code for displaying [System.Drawing.Color] values from a console using ANSI escape sequences. After I published the article, I realized what I really wanted was a color palette display that wouldn&#8217;t be affected by the console background. A Windows Presentation Foundation (WPF) form would do the&#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":"New on the blog: More colorful fun with #PowerShell","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8,518],"tags":[224,534,540,379],"class_list":["post-8871","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","category-wpf","tag-function","tag-powershell","tag-scripting","tag-wpf"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>More Colorful Fun with PowerShell &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"I continue my fun with displaying colors using PowerShell by creating a WPF proof-of-concept function to display a System.Drawing.Color.\" \/>\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\/8871\/more-colorful-fun-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"More Colorful Fun with PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I continue my fun with displaying colors using PowerShell by creating a WPF proof-of-concept function to display a System.Drawing.Color.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-14T15:56:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-14T15:56:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"More Colorful Fun with PowerShell\",\"datePublished\":\"2022-02-14T15:56:48+00:00\",\"dateModified\":\"2022-02-14T15:56:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/\"},\"wordCount\":669,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/textbox-background.png\",\"keywords\":[\"Function\",\"PowerShell\",\"Scripting\",\"WPF\"],\"articleSection\":[\"PowerShell\",\"Scripting\",\"WPF\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/\",\"name\":\"More Colorful Fun with PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/textbox-background.png\",\"datePublished\":\"2022-02-14T15:56:48+00:00\",\"dateModified\":\"2022-02-14T15:56:52+00:00\",\"description\":\"I continue my fun with displaying colors using PowerShell by creating a WPF proof-of-concept function to display a System.Drawing.Color.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/textbox-background.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/textbox-background.png\",\"width\":765,\"height\":213},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8871\\\/more-colorful-fun-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"More Colorful Fun with PowerShell\"}]},{\"@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":"More Colorful Fun with PowerShell &#8226; The Lonely Administrator","description":"I continue my fun with displaying colors using PowerShell by creating a WPF proof-of-concept function to display a System.Drawing.Color.","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\/8871\/more-colorful-fun-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"More Colorful Fun with PowerShell &#8226; The Lonely Administrator","og_description":"I continue my fun with displaying colors using PowerShell by creating a WPF proof-of-concept function to display a System.Drawing.Color.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2022-02-14T15:56:48+00:00","article_modified_time":"2022-02-14T15:56:52+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"More Colorful Fun with PowerShell","datePublished":"2022-02-14T15:56:48+00:00","dateModified":"2022-02-14T15:56:52+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/"},"wordCount":669,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.png","keywords":["Function","PowerShell","Scripting","WPF"],"articleSection":["PowerShell","Scripting","WPF"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/","name":"More Colorful Fun with PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.png","datePublished":"2022-02-14T15:56:48+00:00","dateModified":"2022-02-14T15:56:52+00:00","description":"I continue my fun with displaying colors using PowerShell by creating a WPF proof-of-concept function to display a System.Drawing.Color.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/textbox-background.png","width":765,"height":213},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8871\/more-colorful-fun-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"More Colorful Fun with PowerShell"}]},{"@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":6879,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6879\/the-powershell-magic-8-ball\/","url_meta":{"origin":8871,"position":0},"title":"The PowerShell Magic 8 Ball","author":"Jeffery Hicks","date":"October 28, 2019","format":false,"excerpt":"[I updated this article to reflect minor changes in the code and the release of PowerShell 7. This article was originally published 28 October, 2019]. Last year I shared some PowerShell code on Twitter about this time of year. I have a short script that uses Windows Presentation Foundation (WPF)\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\/2019\/10\/8balloracle-2_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/8balloracle-2_thumb.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/8balloracle-2_thumb.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/10\/8balloracle-2_thumb.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":8684,"url":"https:\/\/jdhitsolutions.com\/blog\/wpf\/8684\/creating-a-powershell-clock\/","url_meta":{"origin":8871,"position":1},"title":"Creating a PowerShell Clock","author":"Jeffery Hicks","date":"November 9, 2021","format":false,"excerpt":"I've published a new project to the PowerShell Gallery. This is something that I needed, and maybe you do as well. Even though I have the typical clock running in the Windows taskbar, I have an ultrawide monitor so it isn't always easy to read. I had been running the\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/11\/sample-2.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":6035,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6035\/making-short-links-long-with-powershell-and-wpf\/","url_meta":{"origin":8871,"position":2},"title":"Making Short Links Long with PowerShell and WPF","author":"Jeffery Hicks","date":"July 9, 2018","format":false,"excerpt":"Sometimes, when I have nothing better to do, I kill some time giving Todd Klindt and Shane Young a hard time during their podcast. You should join me sometime. Anyway, during a recent show Todd mentioned a bit of PowerShell code he put together to resolve short links. You see\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\/2018\/07\/image_thumb-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/image_thumb-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/image_thumb-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/07\/image_thumb-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5816,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5816\/a-powershell-input-tool\/","url_meta":{"origin":8871,"position":3},"title":"A PowerShell Input Tool","author":"Jeffery Hicks","date":"December 7, 2017","format":false,"excerpt":"In PowerShell, the primary means to get interactive input from a user is with the Read-Host cmdlet. There's nothing wrong with it but sometimes if you are using it in a graphical tool like the PowerShell ISE or VS Code you may not realize you are being prompted. Or perhaps\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\/2017\/12\/image_thumb-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":8877,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8877\/even-more-colorful-fun-with-powershell-and-wpf\/","url_meta":{"origin":8871,"position":4},"title":"Even More Colorful Fun with PowerShell and WPF","author":"Jeffery Hicks","date":"February 16, 2022","format":false,"excerpt":"Let's continue looking at how to use PowerShell and a Windows Presentation Foundation (WPF) form to display [System.Drawing.Color] values. This article builds on an earlier post so if you missed it, take a few minutes to get caught up. As I did earlier, before running any WPF code in PowerShell,\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\/02\/all-colors-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/all-colors-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/all-colors-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/02\/all-colors-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":9154,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9154\/a-wpf-countdown-timer\/","url_meta":{"origin":8871,"position":5},"title":"A WPF Countdown Timer","author":"Jeffery Hicks","date":"October 19, 2022","format":false,"excerpt":"Last year I released a PowerShell module called PSClock. The module contains a command to create a transparent WPF form displaying a clock. Shortly after, someone posted a request for a countdown timer. Not an unreasonable request and one I finally got around to implementing. However, I already had a\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"pscountdown timer","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8871","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=8871"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8871\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}