Skip to content

Instantly share code, notes, and snippets.

@farukyildiz
Created July 1, 2021 23:36
Show Gist options
  • Save farukyildiz/e5d2b1764235f53a9240d46aa532ea13 to your computer and use it in GitHub Desktop.
Save farukyildiz/e5d2b1764235f53a9240d46aa532ea13 to your computer and use it in GitHub Desktop.
Powershell screenshot
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
$screens = [Windows.Forms.Screen]::AllScreens
$top = ($screens.Bounds.Top | Measure-Object -Minimum).Minimum
$left = ($screens.Bounds.Left | Measure-Object -Minimum).Minimum
$width = ($screens.Bounds.Right | Measure-Object -Maximum).Maximum
$height = ($screens.Bounds.Bottom | Measure-Object -Maximum).Maximum
$bounds = [Drawing.Rectangle]::FromLTRB($left, $top, $width, $height)
$bmp = New-Object System.Drawing.Bitmap ([int]$bounds.width), ([int]$bounds.height)
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save("$env:USERPROFILE\test.png")
$graphics.Dispose()
$bmp.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment