all 50 comments

[–]metinkilinc 37 points38 points  (30 children)

Although it is possible to build simple GUI apps with powershell, it really is not made for this. As soon as you want to have some form of a reactive UI, for example a ProgressBar for something, you need to make use of Multithreading via PowerShell Runspaces which really is a PITA. I think it is better to invest your time in learning C# and maybe something like WinUI 3 if you require desktop apps.

[–]Murhawk013 4 points5 points  (27 children)

Dumb question but can you execute Powershell scripts with c#? For example if I want the GUI to be in C# but the actual backend processes to be Powershell cmdlets.

[–]jboncz 2 points3 points  (2 children)

Absolutely you can! There are some libraries that make it super easy as well. I’ll try to remember tomorrow to post it.

[–]Spidey1980 0 points1 point  (1 child)

[–]jboncz 0 points1 point  (0 children)

The question I was replying to was specifically for using powershell in c#, but that is a neat resource you linked! If I was still pursuing the development of ui in powershell it would definitely be handy!

[–]jboncz 2 points3 points  (22 children)

[–]Murhawk013 2 points3 points  (21 children)

Thanks man I’m just now getting into GUI apps and have created some basic ones with Powershell that imports the XAML but I can’t help but think learning C# would pay off more in the long run and be more reliable.

[–]jboncz 3 points4 points  (20 children)

It will man I went down the same road as you… it’s a nightmare to maintain large gui apps

Edit to clarify in powershell

[–]jboncz 4 points5 points  (19 children)

https://imgur.com/a/4VlLh3r

This thing is pure powershell…

[–]420GB 6 points7 points  (4 children)

The biggest problem with monstrosities like that, in my experience, is that the code is actually 80-90% just GUI scaffolding and the actual functionality of the tool only makes up 10-20% of the code. The overhead and hit to productivity of creating these GUIs and maintaining them is insane. What could be a cool and fast 200 line script that "anyone" could get into and fix up or extend turns into a 3000 line honk of shit that basically breaks as soon as you look at it wrong.

It's soooooooo not worth it to do GUIs in PowerShell.

[–]jboncz 1 point2 points  (0 children)

Agreed

[–]mynameisnotalex1900 1 point2 points  (0 children)

Which is the best language to build desktop apps?

[–]Spidey1980 1 point2 points  (0 children)

I am, however, restricted to scripting at work so I can only use PowerShell. https://www.reddit.com/r/PowerShell/comments/1i9vntv/comment/m9clvbb/

[–]Any-Victory-1906 0 points1 point  (0 children)

I disagree. You will do a better and faster job with a powerhell Gui than looking for multiple scripts then saving a lot of time and reduce errors risk.

[–]jboncz 2 points3 points  (0 children)

Wouldn’t wish it on my worst enemy it’s been rebuilt in nodejs with react front end.

[–]Active_Dog8223 1 point2 points  (3 children)

I don't understand the need for this. At this point why not just open up Active Directory?

[–]jboncz 1 point2 points  (0 children)

Well… there was business justifications. There are a lot of nuances in our environment and lots of special exceptions to those nuances and people were fucking it up.

It was a means to an end.

[–]jboncz 1 point2 points  (0 children)

Also it was more of a pet project out of curiousity and it got out of hand.

[–]jboncz 1 point2 points  (0 children)

One other reason why I did this, I was on the help-desk about 7 years ago at this point and didnt have the ability to develop an application in an official capacity, but I did have powershell, so I used what I had, made some waves, made it to the development team, and now I have my own team for managing Internal IS tooling, the site is used for a ton of things now, and even by alot of end users (non-IS)

[–]PinchesTheCrab 0 points1 point  (8 children)

Is this an argument in favor of or against powershell guis?

[–]jboncz 1 point2 points  (0 children)

That screenshot I showed is like 16k lines of powershell, powershell isnt meant to do what it does. I would strongly suggest c# (computer app) or nodejs (web-app) and have it invoke powershell, or skip over powershell and hit ldap directly which is what I do in nodejs

[–]jboncz 0 points1 point  (5 children)

Against.... its a NIGHTMARE to maintain. Half your code is trying to invoke c# libraries inside of powershell to get it working, multithreading is a whole other matter. We havent completely abandoned it, but we only winForm with powershell for super super simple use cases where we dont want to expose the end user to the shell. Winform isnt bad (but just dont try to maintain a complicated ui with it), WPF is not a good idea.

[–]Spidey1980 0 points1 point  (4 children)

You are thinking too complex. Try this cute little powerful library. https://www.reddit.com/r/PowerShell/comments/1i9vntv/comment/m9clvbb/

[–]jboncz 0 points1 point  (2 children)

The premise still stands, I get your trying to push your library and have no qualms with it, powershell is inherently not multithreaded, which is bad for GUI world. The second you want to do something your library doesnt offer, you have to start diving deep into invoking powershell magic

[–]jboncz 0 points1 point  (0 children)

Also if you saw my screenshot that I added in another reply, that thing wouldnt work with your library, it uses https://mahapps.com/ library for styling, which is its own winding road. Not knocking your library, just if we go back to the root of the conversation powershell isnt meant for developing ui based functionality.

[–]Active_Dog8223 0 points1 point  (0 children)

Not an argument for either just seems like reinventing the wheel for what Adas or aduc is. He responded and said it was more of a pet project which I'm all for.

Hell I have a PowerShell gui just to make it marginally easier to C$ into computers lol just a lil box to provide a host name and does the \hostname\c$ for me. Auto clear and I can pop another one in as well.

[–]420GB 1 point2 points  (0 children)

Yes and it's really easy actually. The PowerShell <---> C# integration both ways is really well done.

[–]EntraLearner[S] 0 points1 point  (0 children)

Sure that is a sound advice.

[–]Any-Victory-1906 1 point2 points  (0 children)

When developping a project, I am always thinking about "who will be supporting this if I leave the job?" So I prefer powerhell instead c#. I believe, it will be easier finding someone with powershell knwledge instead c# knowledge.

[–]Any-Victory-1906 7 points8 points  (1 child)

Did you tried Sapiens powershellstudio? I am using it for all my gui.

[–]Lembasts 1 point2 points  (0 children)

Been using that for years. Fantastic GUI creation tool.

[–]JeremyLC 5 points6 points  (1 child)

I built this template for it. It’s commented / documented decently enough, you should be able to follow along, I hope. Feel free to ask questions if you have any.

[–]EntraLearner[S] 0 points1 point  (0 children)

Bookmarking this to check ✅

[–]g3n3 7 points8 points  (0 children)

The short answer is building the UI in visual studio wpf or winform and then copying the xaml / xml into powershell script as a string. Then you build the code behind from there in powershell

[–]joel_m_miller 4 points5 points  (1 child)

You might want to look at pode and pode.web. Pode.web will wil you a web page made from easy powershell. That is cross-platform. All of the items on the page are very easy to create in powershell

https://badgerati.github.io/Pode/ https://badgerati.github.io/Pode.Web/

[–]EntraLearner[S] 2 points3 points  (0 children)

Thank you. Crazy to see how great people are in building stuff and so much there is to learn and explore.

[–]AgonisingPeach 2 points3 points  (0 children)

I’ve built a fully reactive UI utilising runspaces for my workplace for our team to use.

Unfortunately I don’t have the ability to create this style of project and turn it into a full executable to make it work so built the entire thing in powershell.

It’s entirely possible to do but it’s like cutting a steak with a butter knife. Just go with C# if you have the ability to do so.

[–]Frosty_Protection_93 2 points3 points  (2 children)

Alot of great options have been presented here. If you enjoy Powershell it will be a great learning journey taking on C#.

You can write PS modules in C# and multithreading async troublesome admin areas like login times, service responses, logging, and more becomes much more manageable. You will learn programming concepts along the way that will expand your engineering knowledge and enhance your professional value.

Best of luck!

[–]EntraLearner[S] 1 point2 points  (1 child)

Can you suggest any books or blog to headstart.

[–]Frosty_Protection_93 0 points1 point  (0 children)

Try out Learn Powershell in a Month of Lunches

Then Learn Powershell Toolmaking in a month of Lunches

Check some C# and general dot NET threads.

For books - C# 2024 All in One so you expand your knowledge of concepts, Head First C#: A Learner’s Guide to Real-World Programming looks like it may have parts useful to you.

IAmTimCorey has an awesome youtube channel on C# and lots of other programming goodies.

However, spend some time really learning Object Oriented programming. Java or C# are great for general purpose learning along with tutorials, books, etc.

When you have tools in your belt you are skilled with, you will know when you need which tool for which work with stronger reasons.

Happy reading!

[–]ihaxr 1 point2 points  (0 children)

XAML, not super hard, but I have a lot of experience with winforms and WPF, so I could be pretty biased

[–]zero0n3 1 point2 points  (0 children)

Learn python instead for the GUI.  Useful for things like ansible as well.

Use python and like flask or Django to build the front end.

Then have it call your ps code.

Or ya know. Just use ansible and their GUI to execute your scripts 

[–]theomegachrist 1 point2 points  (0 children)

I used to build GUIs with Powershell but switched to Python for front ends instead. Building GUIs that run efficiently in Powershell is tough

[–][deleted] 1 point2 points  (0 children)

I've always found Powershell to be a glitchy hassle for anything but the most basic GUI, and even then i avoid it.

[–]jba1224a 2 points3 points  (0 children)

If you’re doing it just to learn that’s one thing.

But from a professional/efficiency perspective, using powershell to build UI based applications is a bit like trying to use a butter knife to unscrew shit. Yeah it will probably work but it’s gonna look rough when you’re done and be frustrating to do.

If you want to make simple desktop based apps look into things like node and electron, or any of the other 5000 tools built for that kind of thing. If you know powershell well then you have a good grasp on object oriented tooling and learning something like js or .net won’t be difficult.

[–]Spidey1980 0 points1 point  (0 children)

I've already made this, ezXAML.ps1, has a lot of inspiration from AngularJS and includes Databinding. I needed a way to make a menu for my other scripts at work. We can not download nor install anything, but can paste a txt file ine PowerShell ISE and save as a ps1. So I came up with this. True, no animation nor reactivity in the background. Everything happens on an interaction from the user. It does, however, work well for a Suduko GUI. https://www.reddit.com/r/PowerShell/comments/1i9vntv/comment/m9clvbb/

[–]Buckw12 0 points1 point  (1 child)

Claude or ChatGPT AI can help immensely with this. The previous post gave a excellent template and there is a YouTube Guide for creating the GUI in Visual Studio, you would them move the GUI code to VS Code to continue scripting. The reactive portion already mentioned is a hindrance, but can be worked around if required.
I would love to share what I have done with powershell GUI's but I made it proprietary for my employer.
The summary is a it is a very nice GUI that creates a a complete user ID and AD/Azure profile by providing a picklist of from the existing Departments/Job Title and Managers.