forked from farag2/Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capture_screen.ps1
35 lines (32 loc) · 953 Bytes
/
Capture_screen.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# https://www.pdq.com/blog/capturing-screenshots-with-powershell-and-net/
function Capture-Screen
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]
$Path
)
if (-not (Test-Path -Path $Path))
{
New-Item -Path $Path -ItemType Directory -Force
}
$FileName = "$(Get-Date -f yyyy-MM-dd_HHmmss).bmp"
$File = "$Path\$FileName"
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$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 -TypeName System.Drawing.Bitmap -ArgumentList $Width, $Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
$bitmap.Save($File)
}
Capture-Screen -Path D:\1