PowerShell Script Utility GUI

At my current place of business, a need arose for graphic user interface to manage / execute PowerShell scripts on an end-user’s system. The idea is to have a GUI that we can have a Service Desk tech open, on any company system, for them to run various PowerShell scripts for easy management. I decided to take this on as a personal side project, so I got the parameters and set to work. This GUI needed to do the following:

  • It must be written in a native scripting language so that it can be easily implemented and maintained across multiple versions of Windows.
  • Must be able to display information about each script including: Title, Version, Publish Date, Author, and Purpose.
  • Must allow for the following configurable options:
    • Execute script with “Run As” permissions
    • Ability to set script location to any directory. Some environments may only allow execution of PowerShell scripts from certain directories.
    • Allow custom branding for company color themes, logo, and naming.
    • Allow customization of information pulled from scripts

Thus, the PowerShell Script Utility was born!  Please be sure to check out the code on GitHub and questions, requests, and bugs: https://github.com/michael-g-tgtm/PowerShell-Script-Utility/

Configuration

At the top of the script, you’ll notice there are 8 variables that can be configured. Other values in the script can be change, but these are the main ones used to configure various options. See the below explanations of each one.

$LaunchFromEXE = $false # If you plan to use something like PS2EXE, set this to $true before you convert
$ExecScripsWithRunAs = $false # If you want scripts to be run as a different user, set to $true
$ScriptDirectory = $null # If you have a custom path (like C:\scripts), set value here. Leave $null if you want to use default script directory
$PanelColor = "#666666" # Set the color of the side panel
$PanelImageName = "assets\logo.png" # Set the custom image file of logo you wish to use. Please use assets folder in Root of script.
$WindowIconImage = "assets\icon.ico" # Set the custom icon of the GUI. Please use assets folder in Root of script.
$ScriptName = "PowerShell Script Utility v1.0" # Set the title of GUI script

LaunchFromEXE

This variable is used to change the pathing when the script is wrapped in an EXE file. When set to True, the script will get the directory of the executed process and store it as $PSScriptRoot. When set to False, it changes $PSScriptRoot to a PowerShell v2 friendly format.

ExecScripsWithRunAs

Quite simply, when set to True the GUI will execute all scripts with the RunAs verb to allow for elevated consoles. When set to False, it just uses the Open verb.

ScriptDirectory

On the GitHub page, take note of the directory structure. By default, without changing any variables, the PowerShell Script Utility will use 2 directories located on the same level as the script: scripts and assets. Alternatively, you can set the variable to a path of your desire for scripts.

PanelColor

As the name implies, this variable holds the Hexadecimal color value for the left pane. All Hexadecimal values should be accepted.

PanelImageName

This variable sets the path and name of the panel image on the left. When the image is set later in the script, it will call $PSScriptRoot\$PanelImageName. That translates to “Directory the script was run from” \ “name of image folder and file name”. By default, this value is set to “assets\logo.png”

WindowIconImage

PowerShell allows you to set the small icon on the top left of a GUI, so why not make it customizable? I’ve included a PSSU icon by default that was created in GIMP. You should be able to base your own custom icon off of that one.

ScriptName

This value simply changes the name of the GUI window. It can be changed and has no effect other than changing the window name.

valueName

This array specifies what script information the GUI pulls in. The section below covers the basics, but by default it pulls in the following data: “Name”, “Version”, “Author”, “Description”, “Path”, “ProjectUri”, “CompanyName”

Pulling in Script Information

In order to pull in the script information, as seen in the screenshot, you need to use PowerShell’s ScriptFileInfo format. This means that each script will need the following lines (minimum) at the top of the file:

<#PSScriptInfo

.VERSION 1.0

.GUID <generate-script-Guid>

.AUTHOR Michael Garrison

>

<

.DESCRIPTION 

>

The GUI can pull the data from this block and add it to the text box. Future revisions may allow for custom script info tags, for now this is the only way. For more info on ScriptFileInfo and for a full list of attributes, please visit https://docs.microsoft.com/en-us/powershell/module/powershellget/new-scriptfileinfo?view=powershell-6

Script States

Below are screenshots of the 4 main states of the GUI.

Initialization:

When the PSSU GUI is initially run, no script is selected.

Scrolling Script Pane:

Once you reach a certain number of scripts (around 9 with the default dimensions), a scroll bar will appear and the text boxes will shift.

Script Selection:

When you select a script on the list, the details will display on the right and the Run Script button will update.

Script Execution:

When you click Run Script, the GUI will open a new PowerShell window and run the selected script.

This is the first major script (is 200 lines really major?) that I’m posting publicly, so please be constructive.  I already have more features in mind and I plan on updating the GitHub with bug fixes as they are found. Please be sure to check out the code on GitHub and questions, requests, and bugs: https://github.com/michael-g-tgtm/PowerShell-Script-Utility/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.