forked from hematic/Powershell-Scripts-and-Functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Take Screenshot.ps1
31 lines (29 loc) · 1.03 KB
/
Take Screenshot.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
function Get-ScreenCapture
{
param(
[Switch]$OfWindow
)
begin {
Add-Type -AssemblyName System.Drawing
$jpegCodec = [Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() |
Where-Object { $_.FormatDescription -eq "JPEG" }
}
process {
Start-Sleep -Milliseconds 250
if ($OfWindow) {
[Windows.Forms.Sendkeys]::SendWait("%{PrtSc}")
} else {
[Windows.Forms.Sendkeys]::SendWait("{PrtSc}")
}
Start-Sleep -Milliseconds 250
$bitmap = [Windows.Forms.Clipboard]::GetImage()
$ep = New-Object Drawing.Imaging.EncoderParameters
$ep.Param[0] = New-Object Drawing.Imaging.EncoderParameter ([System.Drawing.Imaging.Encoder]::Quality, [long]100)
$screenCapturePathBase = "$pwd\ScreenCapture"
$c = 0
while (Test-Path "${screenCapturePathBase}${c}.jpg") {
$c++
}
$bitmap.Save("${screenCapturePathBase}${c}.jpg", $jpegCodec, $ep)
}
}