title: Inserting image into SQL Server column of type VARBINARY(MAX) using Powershell
body: <p>I'm stuck. I'm trying to insert a picture from my hard drive to a SQL Server column of type <code>VARBINARY(MAX)</code>. I have it converting to something, but I'm not even sure what it is. What comes out looks like "81 69 20 0 81 69 20 0 81 69 20 0 81 69 20 0 81 69 20 0 81 69 20 0 81" but much longer. In my update command if I replace $file with 01234 that updates without any problem so I'm almost sure it's a matter of converting it into the proper format whatever that may be.</p>
  
  <pre><code>$i = 1
  $shape|foreach{
  if ($shape.Item($i).name.Substring(0, 7) -eq 'Picture')
      {
          #write-host $shape.Item($i).name
          $shape.Item($i).copy()
  
          #write-host $firstChart.name
          $firstChart.paste()
          $firstChart.Export("c:\temp\pictures\image1.jpg", "JPG")
          #$firstChart.Delete
  
          [Byte[]]$file = get-content -Encoding Byte C:\TEMP\pictures\image1.jpg
  
          #$file = [convert]::ToBase64String((get-content C:\TEMP\pictures\image1.jpg -encoding byte))
  
          $cmd.CommandText ="UPDATE QuoteData SET PII_Image1 = $file Where QuoteNumber =  '"+$WorkSheet.Range('G7').Text.replace("'","''")+"'"
          $cmd.ExecuteNonQuery()
      }
      $i++
  }
  </code></pre>