Q: Want to capture screenshot of multiple system using powershell. But don't know how I have multiple system and every system having different display resolution. Minumum display resolution is 1024x768 and Maximum display resolution is 1920x1080. Don't know how to make this code auto adjust according to display resolution.
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
   $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
   $graphics = [Drawing.Graphics]::FromImage($bmp)

   $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)

   $bmp.Save($path)

   $graphics.Dispose()
   $bmp.Dispose()
}

#NUC bounds
$bounds = [Drawing.Rectangle]::FromLTRB(0, -1080, 1920, 1080)

$PC_name=$(Get-WmiObject Win32_Computersystem).name

$dateandtime = Get-Date -Format yyyy-MM-dd-hh-mm-ss

$path_pcname= "C:\Scripts\Screenshots\" + $PC_name + "_screenshot_" + "$dateandtime"+ ".png"


screenshot $bounds $path_pcname

$limit = (Get-Date).AddMinutes(-15)
$path_todelete = "C:\Scripts\Screenshots\"

# Delete files older than the $limit.
Get-ChildItem -Path $path_todelete -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force

Start-Sleep -Seconds 10


A: You can use System.Windows.Forms.Screen to grab the resolution data.
$monitor = [System.Windows.Forms.Screen]::PrimaryScreen
[void]::$monitor.WorkingArea.Width
[void]::$monitor.WorkingArea.Height

And use like:
$bounds = [Drawing.Rectangle]::FromLTRB(0, -($monitor.WorkingArea.Height), $monitor.WorkingArea.Width, $monitor.WorkingArea.Height)

May have some issues if you have multiple screens or the property doesn't exist for the monitor device.
