Take Screenshots using all Active Monitors PowerShell Code
title: ## Contents
style: nestedList # TOC style (nestedList|inlineFirstLevel)
minLevel: 1 # Include headings from the specified level
maxLevel: 4 # Include headings up to the specified level
includeLinks: true # Make headings clickable
debugInConsole: false # Print debug info in Obsidian console
Overview
Sources:
Code Snippet
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function CaptureScreenshot([Drawing.Rectangle]$Bounds, $Path) {
# Initialize image
$Image = New-Object Drawing.Bitmap $Bounds.Width, $Bounds.Height
$Graphics = [Drawing.Graphics]::FromImage($Image)
$Graphics.CopyFromScreen($Bounds.Location, [Drawing.Point]::Empty, $Bounds.Size)
# Save screenshot
$Image.Save($Path)
# Cleanup
$Graphics.Dispose()
$Image.Dispose()
}
# Initialize path
$BasePath = "C:\screenshots"
if (-not (Test-Path -Path $BasePath -PathType Container)) {
New-Item -Path $BasePath -ItemType Directory -Force
}
# Get monitors
Add-Type -AssemblyName System.Windows.Forms
$Screens = [System.Windows.Forms.Screen]::AllScreens
# Capture monitors
$DateTime = Get-Date -Format yyyyMMddHHmmss
for ($i = 0; $i -lt $Screens.Length; $i++) {
# Initialize screenshot
$Screen = $Screens[$i]
$Left = $Screen.Bounds.X
$Top = $Screen.Bounds.Y
$Right = $Screen.Bounds.X + $Screen.Bounds.Width
$Bottom = $Screen.Bounds.Y + $Screen.Bounds.Height
$Bounds = [Drawing.Rectangle]::FromLTRB($Left, $Top, $Right, $Bottom)
$FileName = "${BasePath}\${DateTime}_${i}.png"
# Capture screenshot
CaptureScreenshot $Bounds $FileName
}
Details
About
This note is about …
See Also
Appendix
Note created on 2024-05-03 and last modified on 2024-05-03.
Backlinks
LIST FROM [[PowerShell - Take Screenshots using all Active Monitors]] AND -"CHANGELOG" AND -"04-RESOURCES/Code/PowerShell/PowerShell - Take Screenshots using all Active Monitors"
(c) No Clocks, LLC | 2024