Skip to content

Instantly share code, notes, and snippets.

@atao
Created July 18, 2017 09:03
Show Gist options
  • Save atao/15192526456c662fe9a75aef521bdc87 to your computer and use it in GitHub Desktop.
Save atao/15192526456c662fe9a75aef521bdc87 to your computer and use it in GitHub Desktop.
Screenshot function
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
$date = Get-Date -Format yyyyMMddHHmmss
$File = "C:\Temp\Shot-$date.bmp"
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = $Screen.Width
$Height = $Screen.Height
$Left = $Screen.Left
$Top = $Screen.Top
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
$bitmap.Save($File)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment