r/PowerShell • • Jul 09 '19

Tutorial on creating PowerShell GUI Applications - Part 2

https://domruggeri.com/2019/07/09/creating-extensive-powershell-gui-applications-part-2/
132 Upvotes

17 comments sorted by

5

u/Ckarini Jul 09 '19

Got a lot of positive feedback on the first article, so I decided to crank this one out. This time we take an in-depth look at Fields, and DataGridViews. If you guys have any suggestions on things you want to do in winforms with PowerShell, let me know!

1

u/lordicarus Jul 09 '19

I've never been a fan of building GUI for PowerShell, but this is really great stuff, keep it up.

In case you're curious, my feeling is that command line tools should stay command line tools. It's basically a sort of philosophical preference. The GUI you are building isn't going to work cross platform (most likely) and depending on things like screen DPI and some of the zoom settings in different versions of Windows, you may end up with things looking really messed up for one user. The command line keeps it all simple. My preference is to create comment based help for each of my more complicated scripts so that every parameter and parameter set is well known and easy to understand.

The most common complaint about GUI with PowerShell is "why not just write the code in VB/C# if you're already designing in VS. The problem with that PowerShell has a ton of modules that make connecting to different services very easy and it's nowhere near as easy, usually, to pull off the same stuff within C#/VB, even if you have more control that way. Sure, you could programmatically create a runspace from within VB/C# in your app that then receives commands based on UI interactions, but that adds even more complexity.

To my very first point, I may not be a huge fan of this, but this is a really good article and so was the first. Great work!

5

u/Ckarini Jul 09 '19

I do agree with you to an extent-I've written many PowerShell scripts and some modules, and I also like to make everything clear as possible. The specific use case came up for me when I was asked to create a set of tools for our Tier 1 Service Desk to use. I tried making a module for them, and was horrified with how they thought the syntax worked. Even with tight-grip hand holding. I think, while as unnatural as it may be, there can be uses for PowerShell apps to have a GUI interface. Thanks for the feedback, and thank you for reading.

2

u/lordicarus Jul 09 '19

Oh yea, there definitely are use cases for it, I'm just not a fan of it is all. I guess what it really comes down to is that if my tier 1 engineers weren't smart enough to follow documentation on how to execute a script, they would no longer be my tier 1 engineers. If they can't be trusted to run a few commands in the command line, then they shouldn't be trusted to be doing any kind of administrative task, GUI or otherwise.

1

u/Ckarini Jul 09 '19

Haha, yeah I couldn't agree more with that last part.

4

u/sysiphean Jul 09 '19

if my tier 1 engineers weren't smart enough to follow documentation on how to execute a script, they would no longer be my tier 1 engineers.

Oh that we could control who our tier 1s (or 2s, or 3s...) are in most organizations.

2

u/Simon-is-IT Jul 09 '19

Yep. I'd be happy if our T1 or T2 even knew what PowerShell was...nevermind what a module is or the syntax for a command.

2

u/Reverent Jul 09 '19

I pretty much write this on every ps gui post, but this is why I write my guis in electron. It's cross platform (with PowerShell core), dpi friendly, and runs independently of the script. You just need to make up the script to take the right commands, and electron can gather up the parameters and run it for you.

5

u/MmmmSweetLemonade Jul 09 '19

Nice job. There's a ton of potential with WPF, I have written a few that are super helpful.

2

u/Ckarini Jul 09 '19

Yeah, I tried WPF before, but the whole process seemed clunky, and it was difficult to create the forms. That's just me, though.

1

u/MmmmSweetLemonade Jul 12 '19

Did you use VisualStudio for the xaml? Coding it by hand is terribad, but VS makes that part easier. Then you can code the PS by hand.

1

u/Ckarini Jul 12 '19

No no, I used VS, but even the clicking around in the designer for wpf was a weird experience

7

u/RickaliciousD Jul 09 '19

I'm just writing some automation for our Hyper-v estate, so this will come in handy. Thanks!

3

u/[deleted] Jul 10 '19

I didn'y know about the Convert-Form module. That could come in handy. I've been using WPF and just copy and paste the XAML code across from Visual Studio which seems to work for me.

2

u/FunkyJewMonkey Jul 09 '19

Cheers for this. I've been in a bit of a rutt lately with learning new skills, this will jump start things again 👌

1

u/PeterPanLives Jul 09 '19

I'm adding these to my reading list. Thanks

0

u/[deleted] Jul 09 '19

[deleted]

1

u/RemindMeBot Jul 09 '19 edited Jul 10 '19

I will be messaging you on 2019-07-17 22:55:14 UTC to remind you of this link

1 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback