I’ve recently been working on a PowerShell module that uses a CSV file to create a custom menu of scripts.
It looks like this:
It hopefully helps to bridge the gap between engineers and automators, who write scripts useful to others, and service desk people and technicians, who may not be confident with the command line. PSScriptMenuGui allows PowerShell coders to put their scripts in a simple menu, usable by anyone.
It’s loosely inspired by (criminally similar to) something I made for a previous employer.
(The main difference is that this version starts instantly. The old version was so slow that I made an entertaining loading screen to fill the void. A good subject for a future blog post…)
If you’d like to dive straight in, please:
The rest of this blog post acts as a tutorial.
If you’d like to be guided through making your own menu, keep reading…
Step 0: System requirements
The module works on Windows only – sorry, rest of world!
Apart from that, it should run pretty much anywhere. It works on:
- PowerShell for Windows 5.1 which comes with Windows 10.
- PowerShell 7, currently available as a preview and due to be finished at the start of 2020.
It does not work on PowerShell Core 6. If you have this version, the easiest solution is to use PowerShell 5.1 as it is already on your PC.
Step 1: Install the module and make an example menu
Open a PowerShell prompt and:
# Navigate to where you want to work on your menu - in my case OneDrive: cd $env:OneDrive # Install the module: Install-Module PSScriptMenuGui -Scope CurrentUser # You may need read and agree to messages about updates and trust # Make an example menu to get you going: New-ScriptMenuGuiExample
You should see this:
VERBOSE: Copying example files to PSScriptMenuGui_example...
Step 2: Explore the example
Navigate to your PSScriptMenuGui_example folder and open PSScriptMenuGui.ps1. You should see a bit of boilerplate to ensure that the module is loaded, followed by this line which displays the menu:
Show-ScriptMenuGui -csvPath '.\example_data.csv' -Verbose
Try running the line in your PowerShell window. You should see the example menu from the GIF at the top of this post.
Now open example_data.csv. A text editor is fine but Excel is easier. You can see that every row in the CSV represents an item in the menu.
Step 3: Make it your own
Experiment with editing the CSV and running the Show-ScriptMenuGui command again to see your changes.
A few ideas:
- Put one of your scripts in the folder and add it to the menu using Method powershell_file and Command .\filename_of_script.ps1.
- Try including PowerShell commands in the CSV file. Use Method powershell_inline and Command Get-ComputerInfo. Run Show-ScriptMenuGui with -NoExit to stop the PowerShell window from closing.
- Add a link to an external application. Use Method cmd and enter the path of the program in Command.
Step 4: Next steps
- Go to GitHub for full documentation. In particular, see the CSV reference.
- Check out PSScriptMenuGui_all_options.ps1 in your PSScriptMenuGui_example folder.
- Run Get-Help Show-ScriptMenuGui -Full
Step 5: Make a shortcut
When you’re happy with your menu, why not make a shortcut to it in File Explorer?
- Right click a blank area in a folder window or on your desktop.
- Select New → Shortcut
- Enter something like this as the location:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\full\path\PSScriptMenuGui_example\PSScriptMenuGui.ps1"