2021-09-27 10:09:45 +02:00
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
.SYNOPSIS
|
2021-09-25 19:43:22 +02:00
|
|
|
take-screenshots.ps1 [<TargetDir>] [<Interval>]
|
2021-07-13 21:10:02 +02:00
|
|
|
.DESCRIPTION
|
2021-09-25 19:43:22 +02:00
|
|
|
Takes screenshots and saves them into a target directory (per default every 60 seconds)
|
2021-07-13 21:10:02 +02:00
|
|
|
.EXAMPLE
|
2021-09-25 19:43:22 +02:00
|
|
|
PS> ./take-screenshots C:\Temp 60
|
2021-08-29 17:50:03 +02:00
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz · License: CC0
|
2021-07-13 21:10:02 +02:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2020-10-03 23:26:33 +02:00
|
|
|
#>
|
|
|
|
|
2021-09-25 19:43:22 +02:00
|
|
|
param([string]$TargetDir = "$PWD", [int]$Interval = 60) # in seconds
|
2021-01-27 10:32:04 +01:00
|
|
|
|
2021-01-27 15:12:17 +01:00
|
|
|
function TakeScreenshot { param([string]$FilePath)
|
2021-01-27 10:44:30 +01:00
|
|
|
Add-Type -Assembly System.Windows.Forms
|
|
|
|
$ScreenBounds = [Windows.Forms.SystemInformation]::VirtualScreen
|
|
|
|
$ScreenshotObject = New-Object Drawing.Bitmap $ScreenBounds.Width, $ScreenBounds.Height
|
|
|
|
$DrawingGraphics = [Drawing.Graphics]::FromImage($ScreenshotObject)
|
|
|
|
$DrawingGraphics.CopyFromScreen( $ScreenBounds.Location, [Drawing.Point]::Empty, $ScreenBounds.Size)
|
|
|
|
$DrawingGraphics.Dispose()
|
|
|
|
$ScreenshotObject.Save($FilePath)
|
|
|
|
$ScreenshotObject.Dispose()
|
2021-01-27 10:32:04 +01:00
|
|
|
}
|
2020-10-03 23:26:33 +02:00
|
|
|
|
2021-01-27 10:32:04 +01:00
|
|
|
try {
|
2021-01-27 10:44:30 +01:00
|
|
|
do {
|
|
|
|
$Time = (Get-Date)
|
|
|
|
$Filename = "$($Time.Year)-$($Time.Month)-$($Time.Day)-$($Time.Hour)-$($Time.Minute)-$($Time.Second).png"
|
2021-09-25 19:43:22 +02:00
|
|
|
$FilePath = (Join-Path $TargetDir $Filename)
|
2021-01-27 10:44:30 +01:00
|
|
|
|
|
|
|
write-output "Saving screenshot to $FilePath..."
|
|
|
|
TakeScreenshot $FilePath
|
|
|
|
Start-Sleep -Seconds $Interval
|
|
|
|
} while (1)
|
2021-09-27 10:09:45 +02:00
|
|
|
exit 0 # success
|
2021-01-27 10:32:04 +01:00
|
|
|
} catch {
|
2021-09-16 20:19:10 +02:00
|
|
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
2021-01-27 10:32:04 +01:00
|
|
|
exit 1
|
2020-10-03 23:26:33 +02:00
|
|
|
}
|