How to Create a Powershell Menu GUI

by Danny
3 comments

READING TIME: 8 MINUTES

In this guide, I’m going to show you an incredibly simple way to create a menu to display all of your most-used Powershell scripts.

In this tutorial, I am using PSScriptMenuGui. This module uses a simple 6-column .CSV file, which is where you will specify things like the script path, button name, section, and description. I went with this option because it was by FAR the easiest way to create a simple menu for myself and our IT department to use and manage. I didn’t want to spend the time to cobble together something using Windows Presentation Framework (WPF) or use PoshGui, because based on some of the other guides I’ve found online – that could be a very long and daunting process.

All I want is a simple way to click a button and run a Powershell script, so PSScriptMenuGui fit the bill and works really well.

Note: I have links below for each of the scripts in my header image.


Why use a Powershell GUI?

There are a number of reasons why you should consider using a GUI to manage your scripts. Here’s why I use one:

  • Quickly access your most used scripts
  • Organize scripts
  • Simplifies onboarding/offboarding of new hires or terminated employees
  • Allows you to share your scripts with other employees (without them having to right-click and Run With Powershell)
  • Deploy scripts in one-button click
  • Give additional notes about what each script does in case there is any confusion

Let’s say you are in the process in the automating your new hire process.

You start creating Powershell scripts for things like Create New Active Directory User, Create O365 mailbox, move the user to a certain OU, send a welcome email, etc.

That’s great! Unfortunately, now you are left with a folder full of scripts.

How do you delegate running these scripts for your IT staff? Do you just name the scripts Step1_NewADuser.ps1, Step2_CreateO365user.ps1?

This was exactly the same problem I ran into, and why a Powershell GUI makes the most sense. With this solution, the file name doesn’t really matter because they are just clicking a button. You can also add a description to give more context before the user runs the script, or simply use the description field to number your steps.

If this is something you’d like to setup, follow the instructions below.


Step 1: Install Powershell Script Menu Gui

The Github link to this project can be found here: https://github.com/dan-osull/PowerShell-Script-Menu-Gui

Open Powershell and type this command:

Install-Module -Name PSScriptMenuGui

Click Yes in the popup box to install the Nuget repositories.

Click Yes to All on the external repositories box:

That’s it, the module is now installed.


Step 2: Create CSV File

To simplify things, you should create a folder where you’ll be dropping your completed files into. This is also where your .csv file will go. (mine is named ITgui.csv in the image below)

I created a C:\Scripts\Final folder, which is where all my completed scripts will go.

In your newly created .csv file, add these 6 column headers: Section, Method, Command, Arguments, Name, and Description.


Step 3: Add Your Scripts

I’m only adding Powershell scripts to mine, but you can add Windows programs and CMD commands to this as well.

The rest is pretty self-explanatory. You can reference my .csv above to give you an idea of how to lay things out.

  • Sections: Give your section a name (i.e – New Hire.) All scripts with the same section name will be grouped together in the frontend menu.
  • Method: Valid options here are:
    • powershell_file
    • cmd
    • powershell_inline
    • pwsh_file, pwsh_inline
  • Command: Path to script or executable
  • Arguments (optional): Specify any arguments you want to pass to the target script
  • Name: Button name
  • Description: Button description

Step 4: Launching Your Powershell Menu

Create a new .ps1 file and paste in the below command. This is the command that will launch your menu script.

The only thing you’ll need to change is the .csv path to the location yours is stored. Then, save your .ps1 script to your Scripts folder (C:\Scripts\Final) and give it a name (IT-Script-GUI.ps1).

Show-ScriptMenuGui -csvPath '.\ITgui.csv' -Verbose

Then, just right-click the IT-Script-GUI.ps1 file > Run With Powershell and your brand new menu should open!

You may notice that this program has the default title Powershell Script Menu, you can’t change the button colors, etc. If you’d like to further customize your menu, you can use the below command inside your .ps1 instead. Just change the .csv path, select a new color, and then change the Window Title fields. Everything else can be left as is.

#region Setup
Set-Location $PSScriptRoot
Remove-Module PSScriptMenuGui -ErrorAction SilentlyContinue
try {
    Import-Module PSScriptMenuGui -ErrorAction Stop
}
catch {
    Write-Warning $_
    Write-Verbose 'Attempting to import from parent directory...' -Verbose
    Import-Module '..\'
}
#endregion

$params = @{
    csvPath = '.\ITgui.csv'
    windowTitle = 'IT Shared Scripts v1.1'
    buttonForegroundColor = 'Azure'
    buttonBackgroundColor = '#eb4034'
    hideConsole = $true
    noExit = $true
    Verbose = $true
}
Show-ScriptMenuGui @params

Step 5: (Optional) Converting your Powershell Script to an EXE

This step is optional, but if you’d like to turn your completed GUI Menu script into an actual program, it’s super easy to do. The main I chose to do this is so I can pin the program shortcut to my taskbar or desktop for quick access.

To do this, I used a program called PS2EXE.

Open a new Powershell instance and type this command to install the module.

Install-Module ps2exe

Then, simply change the Source and Destination paths. The Source is the first path below, the destination where the .exe will go is the second.

Invoke-ps2exe C:\Scripts\Final\IT-Script-GUI.ps1 C:\Scripts\Final\ITtools.exe

Note: The Destination should go to the same folder as your .csv file. Otherwise, the menu won’t load because the CSV file paths will be incorrect. You could also hardcode paths into the .csv.

Obviously having your IT techs browse to a file share to launch the menu isn’t ideal, so let’s create a shortcut.

Just right-click the ITtools.exe from within your Scripts folder > Create a Shortcut. Then, just drag it to your desktop or pin it to your taskbar.

Then, add an icon by right-clicking the shortcut > Change Icon.

You can now pin it to your taskbar for quick access!

For testing, I have the scripts folder on my local machine. Once I provide the Powershell Menu .exe to my IT technicians, I will move the scripts to our IT network share, update the paths in the .csv, and then create a new exe.


Wrapping up

That’s it! Hopefully this guide shows you how to create a Powershell GUI quickly and easily in 2021!

This post is a part of my Automating New Hires With Powershell series, where I create a bunch of helpful Powershell scripts.

3 comments

You may also like

3 comments

Darryl February 24, 2021 - 4:42 pm

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?

Reply
Ravinder July 7, 2021 - 7:56 am

Hi Danny, thanks for sharing, looks great. How can increase the Menu Window to Full Screen?

Reply
Danny July 7, 2021 - 8:01 am

You’re welcome! I still use this everyday and love how easy it is to use once it’s setup.

Good question though – I’m actually not sure. I run mine in the default window. Considering it adds the buttons in a long lost, I don’t know how helpful it would be having it be fullscreen anyway.

Reply

Leave a Comment