r/PowerShell • • Oct 09 '19

PSScriptMenuGui - Use a CSV file to make a graphical menu of PowerShell scripts

289 Upvotes

33 comments sorted by

25

u/weebsnore Oct 09 '19 edited Oct 09 '19

Here's something I've been working on.

Launches fast and works with PowerShell 5.1 and 7-preview!

It's imagined as a good way of sharing scripts with frontline staff.

Useful to anyone?

More here: https://github.com/weebsnore/PowerShell-Script-Menu-Gui

Edit: If you like this, please consider following/retweeting on Twitter. I have pitifully few followers 😁

9

u/froztymug Oct 09 '19

Thank you for sharing, I've been looking for a quicker way to launch my ps1 files and think this will do the trick

3

u/weebsnore Oct 09 '19

Cool! Let me know how you get on.

4

u/Aznflipfoo Oct 09 '19

This is really cool, I've been meaning to build something like this, although now I have no clue how to actually install this and get it setup. Perhaps you could run through a little bit more detailed explanation? I went over your readme, but working with modules and such still confuses me.

4

u/weebsnore Oct 09 '19

No prob!

It's a bit of a manual process right now as the script is an early version. It's not yet in the PowerShell Gallery and it can't be installed with just Install-Module.

Here's what to do:

  1. Install Git on your PC. The installer gives way too many options, but if you keep the defaults you'll be fine. Git is the most common "version control" software for code. It lets you download ("clone") code to your PC.

  2. Restart your PC to be safe. Then open a PowerShell window, navigate to a convenient folder, and run the git clone command from the README.

  3. You now have two folders - an examples folder, and a module folder called PSScriptMenuGui.

  4. Hopefully if you experiment with editing examples\example_data.csv and running examples\PSScriptMenuGui.ps1 you'll be able to get going!

4

u/rebrec Oct 09 '19

The installation of Git is not necessary for end user. Simply download the content of the master branch using this link : https://github.com/weebsnore/PowerShell-Script-Menu-Gui/archive/master.zip

2

u/weebsnore Oct 09 '19

Good thought, thanks. Added to README.

2

u/cyberarchitect Oct 09 '19

^^^^^^^^^^^^^^^^^-------------------this-------------------^^^^^^^^^^^^^^^^^

1

u/nathanieloffer Oct 09 '19

Looks the goods mate. Sadly we are still on Powershell v5.1 on our service desk and there's no plans to update

2

u/weebsnore Oct 09 '19

Works with PS 5.1 too 😊

2

u/zapoklu Oct 09 '19

Powershell 7 and 5.1 can be installed side by side. 5.1 is based on the original .NET framework where version 6 and above are based on .NET core (AKA the new crossplatform one). The support isn't fully there for some of the older Windows based CMDlets so for now they can coexist

1

u/cyberarchitect Oct 09 '19

this should work with PS v5.1, right @weebsnore?

1

u/rebrec Oct 09 '19

Thanks for sharing. Are you opened to pull requests ? Where should new feature be discussed ? by opening an issue ? I had a similar project that i wanted to port to powershell. Your project is a good starter for me so i may contribute to your project or just get inspired from the core gui rendering part depending on what you prefer.

Anyway it's definately a cool contribution. Thank you

2

u/weebsnore Oct 09 '19

Glad you like it!

I'm open to contributions. You can make an issue or drop me an email/PM to chat.

I probably won't add any major features until the base module is finished and in the Gallery though.

License is MIT so feel free to adopt anything that's useful 😊

3

u/rebrec Oct 09 '19

Btw, what is the license of your project ? GPL ? Because there is a copyright withind the psd1

1

u/graysky311 Oct 09 '19 edited Oct 09 '19

JSON would make more sense because it's got a one-to-many structure and even nested objects. Can't do that with CSV without loads of duplication.

Edit: also with JSON you can take advantage of built-in serialization and deserialization of objects and strings which is not something that comes for free with Export-CSV or Import-CSV

2

u/weebsnore Oct 09 '19

I started with CSV because of my target audience and the familiarity/Excel factor, but I wouldn't rule out supporting other formats in the future.

That said - if the project starts needing a more advanced format to be usable, maybe something has gone wrong. It's meant to be simple!

1

u/graysky311 Oct 15 '19

I wanted to mention this. It’s free and simple to generate a menu of commonly used scripts without a lot of coding. Although it mentions SQL it doesn’t have to be used for that. https://www.red-gate.com/simple-talk/sql/sql-tools/sql-scripts-manager-with-powershell/

1

u/boomertsfx Oct 11 '19

YAML is much more human readable

1

u/graysky311 Oct 11 '19

I’ll take your word on that. Have never touched YAML. I’m guessing it’s based on XML?

1

u/boomertsfx Oct 11 '19

Thankfully, no.... It's its own thing and can do everything XML and JSON can do, and it's easier for humans to parse!

1

u/graysky311 Oct 15 '19

I’m not seeing any native PowerShell functionality for working with YAML. Seems like that would not be an obvious first choice for anyone scripting in PowerShell. The YAML project page doesn’t acknowledge PowerShell as a supported language. I would be hesitant to bolt on a third party module just to adopt yet another markup language.

3

u/Catalyst8487 Oct 09 '19

I see so many possibilities for our service desk using this.

3

u/edelwater Oct 09 '19 edited Oct 09 '19

I do the same calling windows forms assembly for stuff, I have a bunch of functions (which could indeed be read by a source file but i find it handier to just have 1 ps1 file. E.g:

function Tskschd { Start-Process -FilePath "$($env:windir)\system32\taskschd.msc"}
function Regedit { Start-Process -FilePath "$($env:windir)\system32\regedt32.exe"}
function SoundVolume { Start-Process -FilePath "$($env:windir)\system32\sndvol.exe"}
function Programs { Start-Process -FilePath "$($env:windir)\system32\appwiz.cpl"}
function Azman { Start-Process -FilePath "$($env:windir)\system32\azman.msc"}
function Cert { Start-Process -FilePath "$($env:windir)\system32\certlm.msc"}
function Services { Start-Process -FilePath "$($env:windir)\system32\services.msc"}
function Firewall { Start-Process -FilePath "$($env:windir)\system32\wf.msc"}
function Tpm { Start-Process -FilePath "$($env:windir)\system32\tpm.msc"}
function Compmgmt { Start-Process -FilePath "$($env:windir)\system32\compmgmt.msc"}
function Comexp { Start-Process -FilePath "$($env:windir)\system32\comexp.msc"}
function Ssms {Start-Process -FilePath "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe"}
function HackerNews {Start-Process -FilePath "https://news.ycombinator.com/"}

I then have: buttons like this:

NewButton -text "TaskScheduler" -execute ${function:Tskschd} -panel $t1

function NewButton {
Param ([string] $text,[System.EventHandler] $execute, [System.Windows.Forms.TabPage]$panel)
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object System.Drawing.Size(200,200)
$button.Text = $text
$button.Add_Click($execute)
$panel.Controls.Add($button)
}

The buttons are placed on a windows forms tabpage inside a tabcontrol with the tabcontrol location on the left to have vertical list of "bookmarks", "apps", "utilities" etc.. I have been thinking on reading the FireFox Bookmarks Sqlite places table for my bookmarks hierarchically and then adding this automatically to the ps1 script in the bookmarks part with a tree control. To have always a synced bookmarks set in 1 ps file and so I dont have to keep the firefox side tab open for all my bookmark folders.

3

u/Lee_Dailey [grin] Oct 09 '19

howdy edelwater,

it looks like you used the New.Reddit.com Inline Code button. it's 4th 5th from the left hidden in the ... "more" menu & looks like </>.

on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.

for long-ish single lines OR for multiline code, please, use the Code Block button. it's the 11th 12th one from the left, & is just to the left of hidden in the ... "more" menu.

that will give you fully functional code formatting, from what i can tell so far. [grin]

take care,
lee

3

u/[deleted] Oct 09 '19

Very cool way to allow less technical coworkers to run the scripts without the "scary terminal". Definitely going to play around with this, thanks for sharing!

2

u/Blindkitty38 Oct 09 '19

Dude your awesome!

2

u/Lazzexus Oct 14 '19

I love this. Been using and running powershellscripts from the PS terminal for quite a while, but my colleagues refuse to use it because they're not as comfortable with PS as I am. Created a .bat-file which runs that script elevated since our logon-accounts don't have admin privileges.

powershell -noprofile -command "&{ start-process powershell -ArgumentList '-noprofile -file C:\pstools\Scripts\PSScriptMenuGui.ps1' -verb RunAs}"

Change the block after -file to the directory where the file is stored, it will prompt for credentials and run as that credential.

1

u/geethreeforce Oct 21 '19

Nice. I was working on simple character-based menus for our servicedesk to allow them to run my recently written unattended installation-scripts which in turn build, install and configure full servers according to their roles. RDS / FilePrint / RODC / Dev

I’ll give this a go. Looks more nice and could save me some time. I’ll blow the horn if I like it. Will post feedback on your PSGallery page.

-18

u/lavahot Oct 09 '19

But why?