Source: Originally from Extract Icon from .EXE Powershell (spiceworks.com) but altered for my needs.
Function Get-ExeIcon {
<#
.SYNOPSIS
Get-ExeIcon extracts the icon image from an exe file and saves it as an Icon (.ico)
file in the defined `-OutputDir`.
.DESCRIPTION
Get-DiskInventory will run on the .exe file and then save the .ico file for and images discovered.
.PARAMETER ExePath
Path to the .exe file
.PARAMETER OutputDir
Directory to output the extracted ico.
.EXAMPLE
# Extract Google Chrome's Icon and Save under ~/Pictures/Icons:
Get-ExeIcon -ExePath "C:\Program Files\Google\Chrome\Application\chrome.exe" -OutputDir "$env:USERPROFILE\Pictures\Icons"
#>
Param (
[Parameter(Mandatory=$true)]
[string]$ExePath,
[Parameter(Mandatory=$true)]
[string]$OutputDir
)
[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($ExePath)
$outputFile = Join-Path $OutputDir "$baseName.ico"
[System.Drawing.Icon]::ExtractAssociatedIcon($ExePath).ToBitmap().Save("$outputFile")
}
Function Get-ExeIconsFromFolder {
<#
.SYNOPSIS
Retrieves icons for each exe file in a folder and saves it as an icon (.ico) file in the same directory as the .exe file.
.DESCRIPTION
Get-DiskInventory will run on every .exe file in the specified directory by the folder PARAMETER then save a .ico file for every .exe discovered.
.PARAMETER Folder
The directory containing the .exe files.
.EXAMPLE
Get-ExeIconsFromFolder -Folder "C:\Program Files\Google\Chrome\Application"
#>
Param (
[Parameter(Mandatory=$true)]
[string]$Folder
)
[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null
md $folder -ea 0 | Out-Null
dir $folder *.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")
}
}
- Code
- Development
- Microsoft
- Microsoft DOS
- Windows Command Line
- 2-Areas/MOCs/PowerShell
- Batch Scripting Tips and Tricks
Backlinks:
list from [[PowerShell - Extract Icon from EXE]] AND -"Changelog"