mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-27 10:23:17 +01:00
34 lines
1.2 KiB
PowerShell
Executable File
34 lines
1.2 KiB
PowerShell
Executable File
#!/usr/bin/pwsh
|
|
<#
|
|
.SYNTAX take-screenshot.ps1 [<directory>]
|
|
.DESCRIPTION takes a single screenshot and saves it into the current/given directory
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
|
#>
|
|
|
|
param($Directory = "$PWD")
|
|
|
|
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 {
|
|
$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
|
|
exit 0
|
|
} catch {
|
|
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|