r/PowerShell • • Jul 07 '19

Tutorial on creating Powershell applications using Visual Studio

https://domruggeri.com/2019/07/06/creating-extensive-powershell-gui-applications-part-1/
197 Upvotes

29 comments sorted by

View all comments

19

u/StartingOverAccount Jul 07 '19 edited Jul 07 '19

OK so this is one those thing I've wondered about a few times. Why would anyone create a GUI using Powershell (for a production task)? I see these posts every once in a while in forums and it just doesn't make sense. This tutorial is with Visual Studio. If you have VS why not just use C# or (shudder) VB? You'll get a much nicer UI, built in error handling, mult-threading (if needed).

This is one of those things just because you can, should you.

(yeah I've setup a couple forms on PS just for the fun factor)

Edit: The wondering is more out of curiosity. I don't have strong opinions for or against it just there are better ways to create a UI

15

u/thankski-budski Jul 07 '19

Speaking for myself, the domain I work in has PowerShell readily available and it is trivial to leverage Windows Forms or XAML GUI's, combined with the simplicity of PSRemoting and CIMSessions makes it an attractive approach, albeit with a 'quick and dirty' feel.

The sheer amount of bureaucracy I would have to wade through to even begin to develop and deploy an executable means for most use cases, it just would not be worth it. It would take several months and a strong business case, whereas with a PowerShell GUI, I can just plonk it into a shared area and give people a shortcut.

I do agree that it might not always be the best tool for the job, alas I seem to spend my life doing things using obscure methods because for one reason or another I just can't do them the proper way.

Although, I would imagine that most enterprise domains are not this restrictive, so I'm probably an edge case.

4

u/dextersgenius Jul 07 '19

The sheer amount of bureaucracy I would have to wade through to even begin to develop and deploy an executable means for most use cases, it just would not be worth it. It would take several months and a strong business case, whereas with a PowerShell GUI, I can just plonk it into a shared area and give people a shortcut.

This is exactly my situation. We also have Applocker enabled across all environments that we manage (including our own devices where we don't have admin access), so we can't just plonk an exe somewhere and expect it to work.

1

u/pertymoose Jul 08 '19

So get a developer certificate and sign your own applications.

5

u/Ckarini Jul 07 '19

I've wondered this myself, when learning how to do this. I'm not too great with Visual Basic or C#, but I understand PowerShell. Login prompts, PowerShell-specific commands, APIs, these are all things I already know how to do in PowerShell, and not in other languages. So, my goal was to allow the other PowerShell scripters to create an application without learning a new programming language.

Also, there are many ways to set up and display the UI which can look just as nice as any C# form. And, I'll be covering Error-Handling in an upcoming article- when we convert this to an exe, the write-warning and write-error commands will do the work for us. And as for the multithreading, we can do that as well with Start-Job.

3

u/StartingOverAccount Jul 07 '19

Fair enough.
To clarify a bit I wasn't implying you can't do any of that in PS. Just the amount of effort required between PS and other languages to accomplish this task.

3

u/Onslaught262 Jul 07 '19

Yeah, I don't know any of those other languages. I'd like to learn C#, specifically because PowerShell is derived from it, but I don't know it now. Tools like this are very helpful for guys (and gals) like me.

2

u/Ckarini Jul 07 '19

Yeah, these things may be easier to do in other languages, but I only know PowerShell, so that's what's easiest for me.

2

u/northendtrooper Jul 09 '19

I work in the govt sector and they basically block any and all compiled code, including .exe's. Which leave very little left. My job entails a lot with Active directory and machine scripts to repair broken software. We've used .hta's in the past but today's world with run-spaces and multi-threading is a god send for 10000s of objects to be created/moved/removed/updated/etc. Powershell just fits the bill.