Beta 42

Research and Development

Menu

PowerShell - Extracting Icons

To extract an icon from a file, use .NET Framework methods. Here is a sample code that extracts all icons from all exe files in your Windows folder (or one of its subfolders) and puts them into a separate folder.

[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')  | Out-Null

$folder = "$env:temp\icons"
md $folder -ea 0 | Out-Null

dir $env:windir *.exe -ea 0 -rec | ForEach-Object { 
    $baseName = [System.IO.Path]::GetFileNameWithoutExtension($_.FullName)
    Write-Progress "Extracting Icon" $baseName
    [System.Drawing.Icon]::ExtractAssociatedIcon($_.FullName).ToBitmap().Save("$folder\$BaseName.ico")
}