r/PowerShell • • Feb 24 '21

How to create a simple Powershell GUI Menu to launch your scripts

https://smarthomepursuits.com/how-to-create-a-powershell-menu-gui/
142 Upvotes

24 comments sorted by

11

u/weebsnore Feb 24 '21

Hey. I'm the author of the module you're using. Thanks very much for taking a look at it - I'm delighted to see it being put to good use!

8

u/smarthomepursuits Feb 24 '21

I was wondering how to contact you and thank you for it, so thank you! Great work on this, it's been super useful and incredibly easy to setup and use.

4

u/weebsnore Feb 24 '21

That's great to hear, thanks very much!

38

u/get-postanote Feb 24 '21 edited Feb 24 '21

Not knocking what you did here, as others have shown similar things in the MS powershellgallery.com and other sites.

Yet, the quickest way to get a simple PowerShell GUI Menu, is to just use Out-GridView and or Show-Command and not write a single line of UX/UI/GUI (WinForm/WPF) code at all.

Well, outside of message box stuff.

Just store your scripts in a set of properly named folders, and read the list from the folders, and process a selection. Need a new set, just add a new folder and read as before.

There have been several recent Reddit Q&A on the topic. Don't let the post titles fool you. Text-based, and Native GUI topics are discussed.

(1) Which way the best for creating text menu in PS scripts? : PowerShell (reddit.com)

Read-Host being ignored by PowerShell : PowerShell (reddit.com)

Sure, the above is not as prettified as yours, but as functional tools, can/will get the job done.

10

u/smarthomepursuits Feb 24 '21

I wasn't aware of that option, so thanks for sharing.

5

u/get-postanote Feb 24 '21 edited Feb 27 '21

No worries, again, nothing wrong with what you shared here, yet, since PowerShell provides many ways to do X or Y thingy, well, u'know. ;-}

It's all about what you want to deliver, and what you want your user experience to be.

Well, that and updates/changes, maintenance, long-term care and feeding, et all.

0

u/serendrewpity Feb 24 '21

!remindme

1

u/RemindMeBot Feb 24 '21 edited Feb 24 '21

Defaulted to one day.

I will be messaging you on 2021-02-25 07:56:52 UTC to remind you of this link

5 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

0

u/[deleted] Feb 24 '21

[deleted]

1

u/deathbypastry Feb 24 '21

Ikr. What a cunt for being helpful. /s

4

u/jack104 Feb 24 '21

Really cool, bookmarked both projects to revisit later.

3

u/smarthomepursuits Feb 24 '21

Thanks! I thought it was pretty cool too and figured others would find a simple gui like this useful.

2

u/dvillaret Feb 24 '21

Hi Danny, thanks for sharing, looks great. Does this allow the option for users to run PS commands as standard user that require admin? E.g. an uninstall script or install printer script?

1

u/smarthomepursuits Feb 24 '21 edited Feb 24 '21

Good question - I suppose it depends on the script. I'm a Standard user and can run every script I've added to my menu without needing admin rights. You may be able to accomplish this by calling a .ps1 in a batch file using RunAs.

2

u/weebsnore Feb 24 '21

There's no built-in way for PSScriptMenuGui to spawn a process as admin (although it is a good idea!)

In your target script, however, it should be straightforward to use one of the variety of methods of triggering PowerShell to elevate .

To be honest, this isn't fresh in my mind right now and I can't remember what the best method *is*, but perhaps someone else knows?

2

u/Draconus0331 Mar 24 '21

I've written a script before that detects if the current session is being run with Administrative privilege or not. If not it prompts for credentials for an admin user and relaunches the script using those credentials. I can share if anyone is interested. Oh, and first post in the forum. Hey!

2

u/4thehalibit Feb 26 '21

I love your blog I have a termination script that is completish LOL I have a section that doesn't make sense to me would you be willing to take a look please DM me

thanks

2

u/smarthomepursuits Feb 26 '21

Thank you! Glad you find it useful.

Sure, can you post the snippet here on Reddit? In case I can't figure it out, hopefully someone in this sub can.

3

u/chapbass Feb 24 '21

Bookmarked. Yeah, there are other ways to do this, but this looks clean on first glance. I love things like this, not for myself, but for others. Especially junior admins who may or may not be comfortable with the command line, this is an easy way to create tools for them and get them to consume them on day one. Then day two they can go back and learn the code.

3

u/lucidhominid Feb 24 '21

Neat, though I prefer the simplicity of a shortcut with this target:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noexit -executionpolicy bypass -Command &{Dir -recurse -filter *.ps1|Select Name,FullName|Ogv -PassThru|%{.$_.FullName}}

1

u/[deleted] Feb 24 '21

[removed] — view removed comment

2

u/smarthomepursuits Feb 24 '21

I posted a couple of them at the end of the blog post. Still working on sanitizing and uploading the rest, but should have those up in a day or two. I'll add to the end of the post once complete and reply back here to let you know.