Building GUI Applications in PowerShell
Courtesy Doug Finke, Dr Dobbs
How many lines of PowerShell code are needed to create a complete working WPF application? Two!
It might seem surprising to write an article on developing UIs with PowerShell, Microsoft’s souped-up command-shell scripting language, but in reality, it makes a lot of sense. As developers, we need to deliver what the user wants, and that deliverable is sometimes a GUI. Being the lazy coder, I like to get my job done in the fewest lines of code possible. It’s quicker, easier, less error-prone, and simpler to maintain if it can be coded in PowerShell. To run the examples I present below, you’ll need ShowUI, the PowerShell module to help build WPF user interfaces in script.
Answer: Two Lines of Code
How many lines of PowerShell are needed to create a complete working WPF application? Two! Here’s the code that yields the result shown in Figure 1.