Use base64 for Images in WPF-based PowerShell Forms

I’m currently building a notification module to let me know when VMware vCenter alerts go off in my home lab. I plan to share it, and wanted to use a non-standard icon, but didn’t want to require a separate download. I knew base64 would be the answer, and ultimately, some C# code from StackExchange helped me figure out what needed to be done.

Here’s what it looks like in my application. Note the image being used in both the popup and the notifyicon itself:


Below is the simplified code I used to display the icon within my application popup. The code contains comments that explains each step. It’s pretty straightforward: a quick conversion, then setting the image source to the converted stream.

Working with PowerShell and WPF makes me realize that *this* is what I always wanted coding to be. Simplified yet powerful!

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in PowerShell, WPF
2 comments on “Use base64 for Images in WPF-based PowerShell Forms
  1. Jon says:

    Thanks so much for posting this! I was scouring the net looking for example code to load an embedded base64 image into an XAML form. I almost lost hope. Your solution was *exactly* what I was hoping to find, elegant and straightforward!

Leave a Reply

Your email address will not be published. Required fields are marked *


Migrating SQL Server?

dbatools is an awesome PowerShell module that helps you migrate entire instances with a single command.

Available from and github

SqlServer Needs You

SqlServer now has a dedicated engineer and Microsoft is asking for our input!

Upvote priorities and cmdlets now


Chrissy LeMaire

Brandon Abshire
View Brandon Abshire, MCDBA's profile on LinkedIn


Chrissy has been awarded the Microsoft MVP for her work in the PowerShell community.

Join us!

Belgian PowerShell
User Group

  SQL PASS PowerShell
Virtual User Group


Upvotes Needed

Help persuade Microsoft to open source SQL Server's PowerShell module, SQLPS.

Upvote now on Microsoft Connect