Created
December 6, 2017 13:47
-
-
Save sub314xxl/152980f99ec88d6dd7e809bcaa6ea9d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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