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.
01Command
$ 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- System.Drawing.Graphics class | Microsoft LearnEvidence: 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
Turn any PNG into JPEG, BMP into PNG, and more using .NET's built-in imaging library — scriptable, batchable, zero third-party tools.
Use Windows Package Manager to install, search, and upgrade thousands of applications from the community repository in one command.
Understand PowerShell's execution policy scopes and set the one that lets you run your own local scripts without gutting the security model.