Published 2025-10-08 by Josue Valentin
Need to grab an icon from a Windows application for documentation, shortcuts, or deployment visuals? Here's how to extract it using PowerShell's native .NET capabilities-no third-party software required.
The Script
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Windows.Forms
# Open file dialog to select EXE
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.Filter = "Executable files (*.exe)|*.exe"
$openFileDialog.Title = "Select an EXE file"
if ($openFileDialog.ShowDialog() -eq 'OK') {
$exePath = $openFileDialog.FileName
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($exePath)
# Convert to bitmap and save as PNG
$bitmap = $icon.ToBitmap()
$outputPath = [System.IO.Path]::ChangeExtension($exePath, "png")
$bitmap.Save($outputPath, [System.Drawing.Imaging.ImageFormat]::Png)
Write-Host "Icon saved to: $outputPath"
# Clean up
$bitmap.Dispose()
$icon.Dispose()
}
How It Works
The script:
- Opens a file dialog to browse for any .exe file
- Extracts the primary application icon
- Converts it to a bitmap
- Saves it as a PNG file in the same directory
Use Cases
- Creating documentation with application icons
- Building custom shortcuts and launchers
- Deployment scripts and imaging
- Asset management and inventory