Added Files
This commit is contained in:
35
Powershell/Scripts/take-screenshots.ps1
Normal file
35
Powershell/Scripts/take-screenshots.ps1
Normal file
@@ -0,0 +1,35 @@
|
||||
<#
|
||||
.SYNTAX take-screenshot.ps1 [<directory>] [<interval>]
|
||||
.DESCRIPTION takes screenshots every 60 seconds and saves them into the current/given directory
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($Directory = "$PWD", [int]$Interval = 60)
|
||||
|
||||
function TakeScreenshot { param([string]$FilePath)
|
||||
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()
|
||||
}
|
||||
|
||||
try {
|
||||
do {
|
||||
$Time = (Get-Date)
|
||||
$Filename = "$($Time.Year)-$($Time.Month)-$($Time.Day)-$($Time.Hour)-$($Time.Minute)-$($Time.Second).png"
|
||||
$FilePath = (Join-Path $Directory $Filename)
|
||||
|
||||
write-output "Saving screenshot to $FilePath..."
|
||||
TakeScreenshot $FilePath
|
||||
Start-Sleep -Seconds $Interval
|
||||
} while (1)
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user