Capture Screenshot, NirSoft NirCmd

if ([Environment]::Is64BitOperatingSystem) {
    $DownloadUrl = "https://www.nirsoft.net/utils/nircmd-x64.zip"
    $DestinationFolder = "$env:SystemDrive\limehawk\nirsoft"
} else {
    $DownloadUrl = "https://www.nirsoft.net/utils/nircmd.zip"
    $DestinationFolder = "$env:SystemDrive\limehawk\nirsoft"
}

$zipFileName = Split-Path -Leaf $DownloadUrl
$destination = Join-Path -Path $DestinationFolder -ChildPath $zipFileName
$exePath = Join-Path -Path $DestinationFolder -ChildPath "nircmd.exe"

# Specifying a separate subfolder for screenshots
$screenshotFolder = Join-Path -Path $DestinationFolder -ChildPath "screenshots"
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$screenshotPath = Join-Path -Path $screenshotFolder -ChildPath "screenshot_$timestamp.png"

try {
    # Create the destination directory if it doesn't exist
    if (!(Test-Path -Path $DestinationFolder)) {
        New-Item -ItemType Directory -Force -Path $DestinationFolder
        Write-Host "Directory created."
    } else {
        Write-Host "Directory already exists."
    }

    # Create the screenshot directory if it doesn't exist
    if (!(Test-Path -Path $screenshotFolder)) {
        New-Item -ItemType Directory -Force -Path $screenshotFolder
        Write-Host "Screenshot directory created."
    } else {
        Write-Host "Screenshot directory already exists."
    }

    # Download the file
    Write-Host "Downloading nircmd..."
    Invoke-WebRequest -Uri $DownloadUrl -OutFile $destination
    Write-Host "Download complete."

    # Unzip the file
    Write-Host "Unzipping file..."
    Expand-Archive -Path $destination -DestinationPath $DestinationFolder -Force
    Write-Host "Unzip complete."

    # Clean up the zip file
    Remove-Item -Path $destination -Force
    Write-Host "Zip file removed."

    # Take a screenshot using nircmd.exe
    Write-Host "Taking screenshot..."
    Start-Process -FilePath $exePath -ArgumentList "savescreenshot $screenshotPath"
    Write-Host "Screenshot saved to: $screenshotPath"
}
catch {
    Write-Host "An error occurred: $_"
    exit 1
}

Script data

Language - PowerShell

Run as - Logged In User

Script timeout duration - 5 Mins