Asking for a way of taking screenshot of 2nd desktop when the desktop is extended in two monitors through windows command line

My desktop is extended in two monitors and I want to take screenshot of desktop of 2nd monitor from command line (cmd/powershell).

Any Idea?


This (untested) PowerShell snippet can get you started. Remember that for an extended screen the pixel coordinates are continuous on both screens, from the left-most screen to the right-most:

$File = "\mypath\myscreenshot.bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = ..2nd monitor width in pixels..
$Height = ..2nd monitor height in pixels..
$Left = ..2nd monitor starting left pixel..
$Top = ..2nd monitor starting top pixel, normally zero..
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
# Save to file
$bitmap.Save($File)