Skip to content

Instantly share code, notes, and snippets.

@jewel-andraia
Created April 14, 2016 00:24
Show Gist options
  • Save jewel-andraia/13b9fe7ea7f3405c04d338f93b399ff8 to your computer and use it in GitHub Desktop.
Save jewel-andraia/13b9fe7ea7f3405c04d338f93b399ff8 to your computer and use it in GitHub Desktop.
Copy image to clipboard using PowerShell
[Reflection.Assembly]::LoadWithPartialName('System.Drawing');
[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');
$filename = 'C:\Users\Administrator\Pictures\background-logo-1024.png';
$file = get-item($filename);
$img = [System.Drawing.Image]::Fromfile($file);
[System.Windows.Forms.Clipboard]::SetImage($img);
@mkanet
Copy link

mkanet commented Feb 16, 2019

FromFile method keeps $file locked until it's released from memory. Add the below line to the end of the script, if necessary to release the file.

$img.Dispose()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment