Wenn man einen Screenshot machen will von seinem Bildschirm, so ist das mittels PowerShell komfortabel möglich, wie folgt:


Add-Type -AssemblyName System.Drawing

function Take-Screenshot {
    $screenWidth = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width
    $screenHeight = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height
    $bitmap = New-Object System.Drawing.Bitmap $screenWidth, $screenHeight
    $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
    $graphics.CopyFromScreen(0, 0, 0, 0, $bitmap.Size)
    $timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
    $filePath = "C:\Screenshots\Screenshot_$timestamp.png"
    $bitmap.Save($filePath, [System.Drawing.Imaging.ImageFormat]::Png)
    $graphics.Dispose()
    $bitmap.Dispose()
    return $filePath
}

# Erstellen des Screenshots-Ordners, falls nicht vorhanden
if (-not (Test-Path "C:\Screenshots")) {
    New-Item -ItemType Directory -Path "C:\Screenshots"
}

# Screenshots in regelmäßigen Abständen machen
while ($true) {
    Take-Screenshot
    Start-Sleep -Seconds 60
}

Wenn man einen festen Ordner eintragen will, so kann man sich die Funktion zur Prüfung auf den Ordner sparen.

Mittels „Start-Sleep“ und dem Parameter „Seconds“ lässt sich das Intervall festlegen. Wenn es nur einmalig passieren soll, so würde folgender Code reichen:

Add-Type -AssemblyName System.Drawing

$screenWidth = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width
    $screenHeight = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height
    $bitmap = New-Object System.Drawing.Bitmap $screenWidth, $screenHeight
    $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
    $graphics.CopyFromScreen(0, 0, 0, 0, $bitmap.Size)
    $timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
    $filePath = "C:\Screenshots\Screenshot_$timestamp.png"
    $bitmap.Save($filePath, [System.Drawing.Imaging.ImageFormat]::Png)
    $graphics.Dispose()
    $bitmap.Dispose()
    return $filePath