Skip to content

Instantly share code, notes, and snippets.

@GlasFrost
Last active June 28, 2017 18:20
Show Gist options
  • Save GlasFrost/520fc8a09289b88ad1cc1811dca9cd12 to your computer and use it in GitHub Desktop.
Save GlasFrost/520fc8a09289b88ad1cc1811dca9cd12 to your computer and use it in GitHub Desktop.
Learning how to PowerShell
# This PowerShell script was written by Luis Hartmann 2017.
# Use at own risk.
# Intended for educational purposes only.
# Includes code that was borrowed and adjusted from http://www.tomsitpro.com/articles/powershell-interactive-menu,2-961.html
function showMainmenu () {
param (
[string]$Title = 'Main Menu'
)
#cls
Write-Host ""
Write-Host "================ $Title ================"
Write-Host ""
Write-Host "1: Addition"
Write-Host "2: Subtraction"
Write-Host "3: Color Check"
Write-Host ""
Write-Host "0: Exit"
Write-Host ""
$input = Read-Host "Please make a selection"
switch ($input)
{
'1' { # Addition
doAddition
pressEnter "Press Enter to return to Main Menu"
}
'2' { # Subtraction
doSubstraction
pressEnter "Press Enter to return to Main Menu"
}
'3' { # Color Check
Write-Host "Let's do a color check!"
colorCheck
pressEnter "Press Enter to return to Main Menu"
}
'0' { # Exit
'See you later!'
exit
}
}
}
# pressEnter
# Promts the user to press enter and then returns
# Optional $message can be given
function pressEnter ($message = 'Press Enter to continue'){
Read-Host $message
return
}
# doAddition
# Prompts the user for two numbers
# Outputs the sum of the given numbers
function doAddition{
Write-Host "Let's add up numbers. A + B = C"
[int]$add_a = Read-Host "Give me number A"
[int]$add_b = Read-Host "Give me number B"
[int]$result = $add_a + $add_b
Write-Host "The result of $add_a + $add_b is" $result
}
# doSubstraction
# Prompts the user for two numbers
# Substracts the second number from the first
# Outputs the result
function doSubstraction{
Write-Host "Let's subtract numbers. A - B = C"
[int]$add_a = Read-Host "Give me number A"
[int]$add_b = Read-Host "Give me number B"
[int]$result = $add_a - $add_b
Write-Host "The result of $add_a - $add_b is" $result
}
# colorCheck
# Outputs an awful lot of colorful lines
function colorCheck{
# Light Colors on Black
Write-Host "black on black" -foregroundcolor "black" -backgroundcolor "black"
Write-Host "blue on black" -foregroundcolor "blue" -backgroundcolor "black"
Write-Host "cyan on black" -foregroundcolor "cyan" -backgroundcolor "black"
Write-Host "gray on black" -foregroundcolor "gray" -backgroundcolor "black"
Write-Host "green on black" -foregroundcolor "green" -backgroundcolor "black"
Write-Host "magenta on black" -foregroundcolor "magenta" -backgroundcolor "black"
Write-Host "red on black" -foregroundcolor "red" -backgroundcolor "black"
Write-Host "white on black" -foregroundcolor "white" -backgroundcolor "black"
Write-Host "yellow on black" -foregroundcolor "yellow" -backgroundcolor "black"
# Dark Colors on Black
Write-Host "darkblue on black" -foregroundcolor "darkblue" -backgroundcolor "black"
Write-Host "darkcyan on black" -foregroundcolor "darkcyan" -backgroundcolor "black"
Write-Host "darkgray on black" -foregroundcolor "darkgray" -backgroundcolor "black"
Write-Host "darkgreen on black" -foregroundcolor "darkgreen" -backgroundcolor "black"
Write-Host "darkmagenta on black" -foregroundcolor "darkmagenta" -backgroundcolor "black"
Write-Host "darkred on black" -foregroundcolor "darkred" -backgroundcolor "black"
Write-Host "darkyellow on black" -foregroundcolor "darkyellow" -backgroundcolor "black"
# Light Colors on White
Write-Host "black on white" -foregroundcolor "black" -backgroundcolor "white"
Write-Host "blue on white" -foregroundcolor "blue" -backgroundcolor "white"
Write-Host "cyan on white" -foregroundcolor "cyan" -backgroundcolor "white"
Write-Host "gray on white" -foregroundcolor "gray" -backgroundcolor "white"
Write-Host "green on white" -foregroundcolor "green" -backgroundcolor "white"
Write-Host "magenta on white" -foregroundcolor "magenta" -backgroundcolor "white"
Write-Host "red on white" -foregroundcolor "red" -backgroundcolor "white"
Write-Host "white on white" -foregroundcolor "white" -backgroundcolor "white"
Write-Host "yellow on white" -foregroundcolor "yellow" -backgroundcolor "white"
# Dark Colors on White
Write-Host "darkblue on white" -foregroundcolor "darkblue" -backgroundcolor "white"
Write-Host "darkcyan on white" -foregroundcolor "darkcyan" -backgroundcolor "white"
Write-Host "darkgray on white" -foregroundcolor "darkgray" -backgroundcolor "white"
Write-Host "darkgreen on white" -foregroundcolor "darkgreen" -backgroundcolor "white"
Write-Host "darkmagenta on white" -foregroundcolor "darkmagenta" -backgroundcolor "white"
Write-Host "darkred on white" -foregroundcolor "darkred" -backgroundcolor "white"
Write-Host "darkyellow on white" -foregroundcolor "darkyellow" -backgroundcolor "white"
}
# Entry Point
while($true)
{
# Go back to main menu no matter what happens
showMainmenu
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment