Skip to content

Instantly share code, notes, and snippets.

View scriptingstudio's full-sized avatar
👍
Awake and ready

Matthew Gray scriptingstudio

👍
Awake and ready
View GitHub Profile
@scriptingstudio
scriptingstudio / icoconverter-win.ps1
Last active August 3, 2026 06:32
ICO to PNG converter demo for Windows PowerShell
function Convert-IcoToPng ([string]$icofile) {
# Runtime validation
if ($PSVersionTable.PSEdition -eq 'Core') {return}
if (-not $icofile -or -not (Test-Path $icofile)) {return}
# ICO validation
$signature = Get-Content -Path $icofile -Encoding Byte -TotalCount 6 -ErrorAction 0
if (([System.BitConverter]::ToInt32(($signature[0..3]),0)) -ne 0x10000) {return}
if (([System.BitConverter]::ToInt16(($signature[4,5]),0)) -gt 1) {return} # single-size
Add-Type -AssemblyName System.Runtime.WindowsRuntime
@scriptingstudio
scriptingstudio / percentbar.ps1
Last active August 1, 2026 06:57
Colorful percent bar demo
function New-PercentBar {
[cmdletbinding()]
param (
[parameter(ValueFromPipeline)]
[alias('inputobject')][decimal[]] $value,
[alias('range')][decimal] $scale,
[int] $barlength,
[consolecolor] $color,
[switch] $hint
)
@scriptingstudio
scriptingstudio / Show-Progress.ps1
Last active July 27, 2026 15:28
Yet another PowerShell inline progress bar
function Show-Progress {
param (
[scriptblock] $scriptblock,
[int] $width,
[consolecolor] $color,
[string] $type, # growth | fill | bounce | tide
[switch] $passthru
)
if (-not $scriptblock) {return}
if ($width -lt 1) {$width = 10}
function prompt {
function Get-LastCmdTime {
$diffPromptTime = $null
$lastCmd = Get-History -Count 1
if ($lastCmd -ne $null) {
$diff = $lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime
$msfractional = $diff.TotalMilliseconds - [Math]::Truncate($diff.TotalMilliseconds)
$ms = $msfractional + $diff.Milliseconds
if ($diff.Hours) {'{0}h:{1}m:{2}s:{3:N2}ms' -f $diff.Hours,$diff.Minutes,$diff.Seconds,$ms}
elseif ($diff.Minutes) {'{0}m:{1}s:{2:N2}ms' -f $diff.Minutes,$diff.Seconds,$ms}
@scriptingstudio
scriptingstudio / import-icon.ps1
Last active July 22, 2026 18:19
PowerShell 7.6+ demo to extract an icon with all native and custom sizes
# Windows Powershell doesn't have [System.Drawing.Icon]::ExtractIcon method
# Neither ExtractIcon* functions from user32.dll have a parameter associated with size
Add-Type -AssemblyName System.Drawing
$Path = 'C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe'
function import-icon ([string]$file, [int]$index=0, [int[]]$sizes) {
#if ([version]'7.6' -gt $PSVersionTable.PSVersion) {return}
if (-not $file) {return} # -or -not (Test-Path $file -ErrorAction 0)
if ($sizes.count) { # normalize sizes
$sizes = @($sizes | Where-Object {$_ -gt 7 -and $_ -lt 257} | Sort-Object -Unique)
@scriptingstudio
scriptingstudio / iconhelper.cs
Last active September 7, 2026 12:36
Yet another icon extractor from DLL,EXE,ICO for C#, PowerShell, and Python
/*
SYNOPSIS : Icon Reader for C#
DESCRIPTION : A utility class that extracts the list of all icons handles (all sizes, all color counts) for a binary file like DLL, EXE, or ICO
UTILITIES : GetTotal, ImportIcons, ExportIcons, Dispose
FEATURES : Export: by size and index, multisize icons, split icon groups by size
VERSION : 4.0
LASTUPDATE : 2026-Sep-5
LINK : https://en.wikipedia.org/wiki/ICO_(file_format)
NOTES : Only builtin sizes are exported; GIF,BMP,JPEG always have the background in black
BACKLOG :
@scriptingstudio
scriptingstudio / Convert-SvgToIco.ps1
Last active July 28, 2026 10:42
Simple SVG to ICO converter
<#
.SYNOPSIS
SVG to Windows ICO converter.
.DESCRIPTION
The script uses Inkscape app to convert SVG to PNG and then ensembles PNGs to a single ICO using .NET.
Key features:
- Multisize ICO
- Just one Inkscape instance per multiple size conversions, i.e. a conversion time is independent on amount of sizes
- Control over SVG exported area
- Ability to replace colors in SVG
@scriptingstudio
scriptingstudio / Export-Icon.ps1
Last active July 21, 2026 19:01
Simple image extractor from exe/dll/osx/cpl files
<#
.SYNOPSIS
An AIO function to export icons stored within .DLL and .EXE files.
.DESCRIPTION
Export-Icon can export icons of all sizes, and all color formats to a number of formats, including bmp, png, jpg, gif, emf, exif, icon, tiff, heif, and webp. In addition, it can also export to a different size. All sizes are native, no scaling, except custom sizes.
This function quickly exports *all* icons stored within the resource file.
Export-Icon is independent on .NET version. It uses a custom icon extractor engine because Windows PowerShell doesn't have [System.Drawing.Icon]::ExtractIcon method (https://learn.microsoft.com/en-us/dotnet/api/system.drawing.icon?view=netframework-4.8.1). In addition, PowerShell 7.6+ [System.Drawing.Icon]::ExtractIcon method has a limited capability. Besides, neither ExtractIcon* functions from user32.dll have a parameter associated with size.
.PARAMETER Path
Mandatory. Position is 0. Specifies a filepath to the resource.
.PARAMETER Output
@scriptingstudio
scriptingstudio / PngIconConverter.ps1
Last active July 9, 2026 17:56
A simple class that converts an image to an icon in PowerShell without losing image color data, unlike System.Drawing.Icon
class PngIconConverter {
static [bool] Convert([System.IO.Stream]$input_stream, [System.IO.Stream]$output_stream, [int]$size, [bool]$keep_aspect_ratio) {
$input_bit = [System.Drawing.Bitmap]::FromStream($input_stream)
if ($input_bit -eq $null) {return $false}
if ($size -lt 1) {$size = 32}
if ($keep_aspect_ratio) {
$width = $size
$height = $input_bit.Height / $input_bit.Width * $size
} else {
$width = $height = $size
@scriptingstudio
scriptingstudio / Convert-BoundParameters.ps1
Last active July 8, 2026 12:47
Convert $PSBoundParameters to command line string
function Convert-BoundParameters ([hashtable]$parameters) {
if (-not $parameters.count) {return}
$params = [System.Text.StringBuilder]::new()
$null = $parameters.GetEnumerator().foreach{
$key,$val = $_.Key,$_.Value
if ($val -is [System.Management.Automation.SwitchParameter]) {
if ($val.IsPresent) {$params.Append(" -$key")}
}
elseif ($val -is [string]) {
if ($val.contains(' ') -or [string]::IsNullOrEmpty($val)) {$val = "'$val'"}