title: How to copy an image to clipboard in powershell
body: <p>I want to take screenshot of a specific part of the current window and copy it to clipboard so I can paste it in my PPT or other documents.</p>
  
  <p>I am able to successfully get the image in bmp format and I unable to find a way to place it into clipboard.</p>
  
  <p>This is my code so far.</p>
  
  <pre><code>[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  function screenshot([Drawing.Rectangle]$bounds, $path) {
  
     $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
     $graphics = [Drawing.Graphics]::FromImage($bmp)
  
     $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
     $bmp.Save($path)
  
     # Create data object.
     $dataObject = New-Object windows.forms.dataobject
  
     # Add generated strings to data object.
     $dataObject.SetData("jpg", $true, $bmp)
  
     # Put data object in system clipboard.
     [Windows.Forms.Clipboard]::SetDataObject($dataObject, $true)
     [Windows.Forms.Clipboard]::SetText("Hello")
  
  }
  
  $bounds = [Drawing.Rectangle]::FromLTRB(0, 100, 700, 500)
  screenshot $bounds "d:\screenshot.png"
  </code></pre>
  
  <p>I have tried other various ways of doing it but not able to crack it.</p>
  
  <p>Even simple text is not being copied to clipboard.</p>
  
  <p>Please give me some suggestion.</p>