Skip to content

Instantly share code, notes, and snippets.

@ChrisMissal
Created September 19, 2013 20:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisMissal/6629742 to your computer and use it in GitHub Desktop.
Save ChrisMissal/6629742 to your computer and use it in GitHub Desktop.
How can I do a screen capture in windows powershell?
[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)
$graphics.Dispose()
$bmp.Dispose()
}
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1000, 900)
screenshot $bounds "C:\screenshot.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment