Command/Installation Menu
A Powershell script that shows a menu of user-defined commands to perform. Also has an "Automatic" option to run through all menu options, waiting for a Y/N input.
Getting Started
Download, unzip, and open the menu.ps1 in any text editor.
DownloadAscii Art
The Ascii art is optional. If you do not want it, remove line 31, containing the code write-host $logo. If you want to replace it, use a Ascii generator tool to make a customer banner. I use the one found here. Be sure the new banner is put in-between the "@ symbols.
Customizing the Menu
Start by modifying the main menu. The name of the menu option name start immediatly after the syntax write-host. There are only 7 options here by default, but more can be appending additional write-host commands to the bottom of the list.
write-host $logo
write-host
#Main Menu
write-host 1. Automatic 1
write-host 2. Automatic 2
write-host 3. Manual 1
write-host 4. Manual 2
write-host 5. Manual 3
write-host 6. Manual 4
write-host 7. Manual 5
#Add additional menu options here
Modifying Commands
The menu works by having a series of if-else statements. These statements wait for a specific number to be pressed, corresponding to one of the if statements. In the example below, the if statement waits for a input on the menu. If the input is 1, the code inside the block will run.
if ($menu_input -eq '1') {
write-host Starting action because '1' was pressed
#Powershell command(s) goes here
write-host Confirmation of action
Automatic Mode
This script uses a auto-prompt mode that runs through a series of Yes/No questions and executes code based on the answer. For example, this automatic mode could be used to install software on employee machines at a business. It could automatically install anti-virus, email, a web browser etc, and than prompt with a simple Yes/No for additional software that not every employee needs, such as accounting software or IT tools.
An example of what this would look like in code is below:
if ($menu_input -eq '1') {
write-host Automatic action as soon as menu option is selected
write-host
####Powershell command(s) that automatically run without a Yes/No prompt go here####
write-host Confirmation of automatic actions complete
write-host
###################### Start of the Yes/No Prompts #####################################
$prompt1response = read-host -prompt "Prompt 1 [Y/N]"
if ($prompt1response -eq 'y') {
write-host
write-host Executing prompt 1 because "y" was pressed on the keyboard
#Powershell command(s) goes here
write-host Confirmation of prompt 1
write-host
read-host Press ENTER to continue...
} elseif ($prompt1response -eq 'n') {
write-host
write-host Skipping because "n" was pressed on the keyboard
Write-Host}
$prompt2response = read-host -prompt "Prompt 2 [Y/N]"
Manual Mode
Manual mode is essentially just selecting a option from the main menu and having it run a specific task (or series of tasks)
Assuming this is option 2 or greater, the elseif statement will be required. The code will look similar to this:
} elseif ($menu_input -eq '2') {
write-host
write-host Manual option 2
#Powershell command(s) for option 2 go here
write-host
read-host Press ENTER to continue...
&$menu
Running the Script
In order to run Powershell scripts on windows, the execution policy needs to be changed. This can be done in an administrative Powershell window by running set-executionpolicy remotesigned.
Personally, I find it easier to run Powershell ISE as an administrator and then copy the command located at the start of the script and run it from there.