Convert image formats with PowerShell and System.Drawing

Turn any PNG into JPEG, BMP into PNG, and more using .NET's built-in imaging library — scriptable, batchable, zero third-party tools.

WindowsFilesdevelopermediaLow risk
Run the FromFile/Save snippet above in Windows PowerShell — swap `[System.Drawing.Imaging.ImageFormat]::Jpeg` for `::Png`, `::Bmp`, `::Gif` or `::Icon` as needed.

01Command

Command
$ Add-Type -AssemblyName System.Drawing; $img=[System.Drawing.Image]::FromFile("C:\pics\photo.png"); $img.Save("C:\pics\photo.jpg",[System.Drawing.Imaging.ImageFormat]::Jpeg); $img.Dispose()

02What it does

System.Drawing's Image class decodes the source file and Bitmap.Save re-encodes it into the ImageFormat you name, all inside PowerShell without installing anything. Batch it by wrapping in a loop: `Get-ChildItem *.png | ForEach-Object { $i=[System.Drawing.Image]::FromFile($_.FullName); $i.Save($_.FullName -replace '\.png$','.jpg'), [System.Drawing.Imaging.ImageFormat]::Jpeg; $i.Dispose() }` — always Dispose to release the file handle. Note the quality trade-offs: converting PNG to JPEG flattens transparency to black or a chosen background, and JPEG is lossy; set JPEG quality via an EncoderParameters object if file size matters. This must run in Windows PowerShell 5.1, since System.Drawing.Common is unsupported in .NET Core on non-Windows and restricted in newer .NET versions.

03Risk

RiskLow risk
RequirementsWindows PowerShell 5.1 (System.Drawing is not available in PowerShell 7+ on some .NET runtimes); JPEG has no transparency, so PNGs with alpha may gain a black background.
!Warning: Forgetting Dispose() keeps the file locked and later renames or deletes fail with 'file in use' — release the handle before moving on.

04Undo

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

05Sources

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

06Related solutions