Read image dimensions in PowerShell with System.Drawing

Load any JPG/PNG/BMP into a System.Drawing.Image and read Width and Height — the quick, native way to check image sizes in scripts.

WindowsimagesmediapowershellLow risk
Run `Add-Type -AssemblyName System.Drawing; $img=[System.Drawing.Image]::FromFile('<path>'); $img.Width; $img.Height` to read the pixel size.

01Command

Command
$ Add-Type -AssemblyName System.Drawing; $img=[System.Drawing.Image]::FromFile('C:\Pictures\photo.jpg'); "$($img.Width) x $($img.Height)"; $img.Dispose()

02What it does

FromFile decodes just enough of the file to expose properties like Width, Height, PixelFormat, and the raw file size — far faster than opening an editor for a sanity check. Always call Dispose() (or wrap in try/finally) because FromFile keeps the file locked until then, which breaks later rename/move operations. Loop over Get-ChildItem *.jpg to build a dimension report, and note this needs Windows PowerShell 5.1 or the Microsoft.Windows.Compatibility pack under PowerShell 7.

03Risk

RiskLow risk
RequirementsSystem.Drawing is available in Windows PowerShell 5.1; it is not supported in PowerShell 7+ on non-Windows, and the file is locked until Dispose().

04Undo

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

05Sources

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

06Related solutions