Adding an BASE64 Icon to a WPF GUI

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:


$script:bitmap = New-Object System.Windows.Media.Imaging.BitMapImage
$bitmap.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($base64)

After this we can simply assign the new icon to the form using the code below:

$window.Icon = $bitmap


Leave a Reply