title: Finding the closest System.Color instance(s) using PowerShell
body: <p>I got this code working in C#. I would like help translating this into an idiomatic PowerShell script which would take an rgb or hex color definition as input and output the top 3 or 5 matches to the console including the color name and the rgb values. I am very new to PowerShell, sorry if this is asking too much.</p>
  
  <pre><code>    private static void FindMyColor()
      {
          System.Drawing.Color targetColor = System.Drawing.Color.FromArgb(red: 0, green: 128, blue: 0);
          var myStuff = EnumerateColors(targetColor: targetColor).OrderBy(tpl =&gt; tpl.Item1).ToList();
          int a = 0; // Pause the debugger here.
      }
  
      private static double GetColorDistance(System.Drawing.Color lhs, System.Drawing.Color rhs)
      {
          double sum = Cube(lhs.R - rhs.R) + Cube(lhs.G - rhs.G) + Cube(lhs.B - rhs.B);
          return Math.Pow(sum, 1.0/3.0);
      }
  
      private static double Cube(int value)
      {
          return (double) (value * value * value);
      }
  
      private static System.Collections.Generic.IEnumerable&lt;Tuple&lt;double, string, System.Drawing.Color&gt;&gt; EnumerateColors(System.Drawing.Color targetColor)
      {
          var candidateColors = EnumerateSystemColors();
          foreach (string colorName in candidateColors.Keys)
          {
              var color = candidateColors[key: colorName];
              double colorDistance = GetColorDistance(lhs: color, rhs: targetColor);
              yield return new Tuple&lt;double, string, System.Drawing.Color&gt;(colorDistance, colorName, color);
          }
      }
  
      private static System.Collections.Generic.Dictionary&lt;string, System.Drawing.Color&gt; EnumerateSystemColors()
      {
          var properties = typeof(System.Drawing.Color)
                  .GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy);
          return properties.ToDictionary(p =&gt; p.Name, p =&gt; (System.Drawing.Color)p.GetValue(null, null));
      }
  </code></pre>