Capture the screen to a PNG with PowerShell

A script-driven screenshot: grab the entire virtual desktop (all monitors) and write it to a timestamped PNG — useful for monitoring, unattended tasks, and scheduled captures.

WindowsScreenshotdevelopermediaLow risk
Run the CopyFromScreen snippet above in Windows PowerShell to save a full-desktop screenshot to your Desktop as screen.png.

01Command

Command
$ Add-Type -AssemblyName System.Windows.Forms,System.Drawing; $b=[System.Windows.Forms.SystemInformation]::VirtualScreen; $bmp=New-Object System.Drawing.Bitmap $b.Width,$b.Height; $g=[System.Drawing.Graphics]::FromImage($bmp); $g.CopyFromScreen($b.Left,$b.Top,0,0,$bmp.Size); $bmp.Save("$env:USERPROFILE\Desktop\screen.png"); $g.Dispose(); $bmp.Dispose()

02What it does

The script reads VirtualScreen bounds (the bounding box of all connected monitors, so multi-monitor setups capture everything), creates a Bitmap of that size, and uses Graphics.CopyFromScreen to blit the screen content into it. Wrap the Save path with a timestamp like `screen_$(Get-Date -Format yyyyMMdd_HHmmss).png` for recurring captures via Task Scheduler. For a single window instead of the whole desktop, use Win32 PrintWindow via Add-Type P/Invoke, or press Win+Shift+S for the interactive Snipping Tool. Runs must happen in an interactive desktop session — a locked screen or disconnected RDP session yields a black image.

03Risk

RiskLow risk
RequirementsWindows PowerShell 5.1; must run in an interactive session (a locked or disconnected RDP screen captures black).
!Warning: Screenshots may capture passwords and personal data on screen — be deliberate about where scheduled capture scripts write their output.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • System.Drawing.Graphics class | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    Evidence: Microsoft documents the Graphics class created from an image via Graphics.FromImage, used as the drawing surface for CopyFromScreen screen captures.

Last verified: 2026-09-17 · Category: Media

06Related solutions