Skip to content

Instantly share code, notes, and snippets.

@sub314xxl
Created December 6, 2017 13:47
Show Gist options
  • Save sub314xxl/152980f99ec88d6dd7e809bcaa6ea9d1 to your computer and use it in GitHub Desktop.
Save sub314xxl/152980f99ec88d6dd7e809bcaa6ea9d1 to your computer and use it in GitHub Desktop.
# Capturing a screenshot
Param(
[Parameter(Mandatory = $true)][string]$Path
)
$FileName = "$env:COMPUTERNAME - $(get-date -f yyyy-MM-dd_HHmmss).bmp"
$File = "$Path\$FileName"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = $Screen.Width
$Height = $Screen.Height
$Left = $Screen.Left
$Top = $Screen.Top
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
# Save to file
$bitmap.Save($File)
Write-Output "Screenshot saved to:"
Write-Output $File
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment