function mainMenu {
$mainMenu = 'X'
while($mainMenu -ne ''){
Clear-Host
Write-Host "`n`t`t My Script`n"
Write-Host -ForegroundColor Cyan "Main Menu"
Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "1"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
Write-Host -ForegroundColor DarkCyan " Submenu1"
Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "2"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
Write-Host -ForegroundColor DarkCyan " Submenu2"
$mainMenu = Read-Host "`nSelection (leave blank to quit)"
# Launch submenu1
if($mainMenu -eq 1){
subMenu1
}
# Launch submenu2
if($mainMenu -eq 2){
subMenu2
}
}
}
function subMenu1 {
$subMenu1 = 'X'
while($subMenu1 -ne ''){
Clear-Host
Write-Host "`n`t`t My Script`n"
Write-Host -ForegroundColor Cyan "Sub Menu 1"
Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "1"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
Write-Host -ForegroundColor DarkCyan " Say hello"
Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "2"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
Write-Host -ForegroundColor DarkCyan " Say goodbye"
$subMenu1 = Read-Host "`nSelection (leave blank to quit)"
$timeStamp = Get-Date -Uformat %m%d%y%H%M
# Option 1
if($subMenu1 -eq 1){
Write-Host 'Hello!'
# Pause and wait for input before going back to the menu
Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
Write-Host "`nPress any key to return to the previous menu"
[void][System.Console]::ReadKey($true)
}
# Option 2
if($subMenu1 -eq 2){
Write-Host 'Goodbye!'
# Pause and wait for input before going back to the menu
Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
Write-Host "`nPress any key to return to the previous menu"
[void][System.Console]::ReadKey($true)
}
}
}
function subMenu2 {
$subMenu2 = 'X'
while($subMenu2 -ne ''){
Clear-Host
Write-Host "`n`t`t My Script`n"
Write-Host -ForegroundColor Cyan "Sub Menu 2"
Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "1"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
Write-Host -ForegroundColor DarkCyan " Show processes"
Write-Host -ForegroundColor DarkCyan -NoNewline "`n["; Write-Host -NoNewline "2"; Write-Host -ForegroundColor DarkCyan -NoNewline "]"; `
Write-Host -ForegroundColor DarkCyan " Show PS Version"
$subMenu2 = Read-Host "`nSelection (leave blank to quit)"
$timeStamp = Get-Date -Uformat %m%d%y%H%M
# Option 1
if($subMenu2 -eq 1){
Get-Process
# Pause and wait for input before going back to the menu
Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
Write-Host "`nPress any key to return to the previous menu"
[void][System.Console]::ReadKey($true)
pause
}
# Option 2
if($subMenu2 -eq 2){
$PSVersionTable.PSVersion
# Pause and wait for input before going back to the menu
Write-Host -ForegroundColor DarkCyan "`nScript execution complete."
Write-Host "`nPress any key to return to the previous menu"
[void][System.Console]::ReadKey($true)
pause
}
if ($subMenu2 -eq 3){
$username = Read-Host("`nEnter domain user account")
if($username -ne "`0"){
net user $username /domain
pause
[void][System.Console]::ReadKey($true)
}else{
echo "Invalid entry"
[void][System.Console]::ReadKey($true)
}
}
}
}
mainMenu