Take a screenshot with PowerShell

Thanks to Jeremy on StackOverflow (http://stackoverflow.com/questions/2969321/how-can-i-do-a-screen-capture-in-windows-powershell), .NET allows us to take a screenshot programatically:

[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 ".\screenshot.png"

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top