Nice and simple one today. I’m going to show you how to add an icon to a WPF GUI in PowerShell using BASE64 data.
I won’t be putting my BASE64 data into this post since its a MASSIVELY long string of characters but it should look something like this ” iVBORw0KG…”
First, we need to create a new variable to hold the data and then use the bitmapimage object to convert the data into a usable icon. You can see this below:
[string]$script:base64=@" iVBORw0KGgo... "@ $script:bitmap = New-Object System.Windows.Media.Imaging.BitMapImage $bitmap.BeginInit() $bitmap.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($base64) $bitmap.EndInit() $bitmap.Freeze()
After this we can simply assign the new icon to the form using the code below:
$window.Icon = $bitmap
Enjoy!