Skip to content

Instantly share code, notes, and snippets.

@wescpy
Last active October 1, 2023 06:14
Show Gist options
  • Save wescpy/c81052fb2f74916a79ac75c87bb53018 to your computer and use it in GitHub Desktop.
Save wescpy/c81052fb2f74916a79ac75c87bb53018 to your computer and use it in GitHub Desktop.
PowerShell script that saves .exe icons as .ico files
<#
.SYNOPSIS
Saves .exe/.msi icons as .ico files (to use with Explorer)
.DESCRIPTION
Loops thru all .exe/.msi files in given or current (default)
folder, extracts icons, and saves them as .ico files.
.PARAMETER folder
Optional folder name; if not provided, current ($pwd) is used
.EXAMPLE
(current folder) ExtractIcon
(another folder) ExtractIcon -folder C:\Users\test
.NOTES
License: apache.org/licenses/LICENSE-2.0
#>
Param (
[string]$folder=$pwd
)
Function ExtractIcon {
[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null
Get-ChildItem $folder\*.* -include *.exe,*.msi -ea 0 |
ForEach-Object {
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($_.FullName)
Write-Progress "Extracting Icon" $baseName
$stream = [System.IO.File]::create("$folder\$BaseName.ico")
[System.Drawing.Icon]::ExtractAssociatedIcon($_.FullName).Save($stream)
$stream.Close()
}
}
ExtractIcon $folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment