Get Color Palette of Image Using PowerShell

I am trying to get the `Color Palette` of an image. I tried various methods, and now I use the following code in `PowerShell`, but I could not get the correct result:

$filename = "C:\Users\schoo\Desktop\bb.jpg"
    $BitMap = [System.Drawing.Bitmap]::FromFile((Get-Item $filename).fullname) 
     
    Foreach($y in (1..($BitMap.Height-1))){ 
      
      Foreach($x in (1..($BitMap.Width-1))){ 
             
             $Pixel = $BitMap.GetPixel($X,$Y)         
             $BackGround = $Pixel.Name
             }
    
    $R = $Pixel | select -ExpandProperty R
    $G = $Pixel | select -ExpandProperty G
    $B = $Pixel | select -ExpandProperty B
    $A = $Pixel | select -ExpandProperty A
    
    $allClr = "$R" + "." + "$G" + "." + "$B" + "." + "$A"
    $allClr  
    }

The result take me more than thousand `RGBA` codes!
I want to get some average RGB codes, please see this result: http://bit.ly/2xo7cuB

Honestly, I’m not sure this is a “PowerShell question” per se. I have zero experience manipulating images, for example. I mention it only because you’re basically doing .NET programming - and you might get a better answer on a dev-focused site like StackOverflow.com. This site ends up just being more about administrative automation than image manipulation… sorry :).

I appreciate you to answer my question, and your sound. in fact i got some fixable code to answering this Q, but now I getting some issue, it maybe you can fixed.
Now I have some member, can I damage or join those together? for example:

PS D:\> $table.Keys | select R, G, B
  R   G   B
  -   -   -
255 240   0
  0 255   0
255 138   0
255   0 234

I want to join R,G,B as like: “255.240.0” extra

You really should take a little time and start to learn the basics of Powershell

$table.Keys | ForEach-Object {($.R,$.G,$_.B ) -join ‘.’}