i am new to this so please explain very basic :wink:

I’ve created a PS script by piecing together lots of code from the Community but…Now i ask you guys if u can help me put the last bit togheter. <333.

So can you please help me with the following → if i wanna run this line for example i put in 1 then enter i want to get that Write-Host that says 1 - test script to execute a command in the code how do i mange to make it do that.

<# # ==================================================================================================== # # Script: PoSHMenuTemplate.ps1 # # Version: 1.0.0 # # Author: Calahan, Cory # # Create date: 2013-07-17 # # Description: PowerShell “batch” menu template. # # Comments: https://stealthfield.wordpress.com # # ==================================================================================================== # #>

Clear-Host
$Host.UI.RawUI.WindowTitle = “PoSH Menu Template”

function loadMainMenu()
{
[bool]$loopMainMenu = $true
while ($loopMainMenu)
{
Clear-Host # Clear the screen.
Write-Host -BackgroundColor darkblue -ForegroundColor White “n


|__ | \ | \ |__ | || | |/| / \ |\ |
|___ |/ |/ |___ | | | |___ | | /~~\ | | tn”

$runasAlias = [Environment]::UserName
Write-Host -BackgroundColor black -ForegroundColor White “Running as: ----> $runasAlias`n”

Write-Host -BackgroundColor darkgreen -ForegroundColor White “t ---->|Huvud meny|<-----ttn” Write-Host “ttt1 - scripts”
Write-Host “ttt2 - Meny (2)” Write-Host “ttt3 - Meny (3)”
Write-Host “ttt4 - Meny (4)” Write-Host “tttQ — Avsluta och stängn” Write-Host -BackgroundColor DarkCyan -ForegroundColor Yellow "obs!: ↴ t" Write-Host -BackgroundColor RED -ForegroundColor White "Du kör detta på egen risk /mvh edvin:J.tn"
$mainMenu = Read-Host “ttcommand to run?” # Get user’s entry.
switch ($mainMenu)
{
1{mainMenuOption1} # Calls function mainMenuOption1()
2{} #To-do: Add.
3{} #To-do: Add.
4{} #To-do: Add.
“q” {
$loopMainMenu = $false
Clear-Host
Write-Host -BackgroundColor DarkCyan -ForegroundColor Yellow “ttttt" Write-Host -BackgroundColor DarkCyan -ForegroundColor Yellow "tGoodbye!ttt" Write-Host -BackgroundColor DarkCyan -ForegroundColor Yellow "ttttt”
sleep -Seconds 1
$Host.UI.RawUI.WindowTitle = “Windows PowerShell” # Set back to standard.
Clear-Host
Exit-PSSession
}
default {
Write-Host -BackgroundColor Red -ForegroundColor White “FEL val för Kommando försök igen.”
sleep -Seconds 1
}
}
}
return
}

function mainMenuOption1()

This section is used for Loading Main Menu Option 1, .

{
[bool]$loopSubMenu = $true
while ($loopSubMenu)
{
$Host.UI.RawUI.WindowTitle = “PoSH Sub Menu 1”
Clear-Host # Clear the screen.
Write-Host -BackgroundColor Black -ForegroundColor White “nt Undermeny 1 (Scripts)tn”
Write-Host -BackgroundColor Black -ForegroundColor White “ttSCRIPTSttn” $runasAlias = [Environment]::UserName Write-Host -BackgroundColor Black -ForegroundColor White "Running as: $runasAliasn"
Write-Host “ttt1 - test script ” Write-Host “ttt2 - Sub Menu 2 - Option 2”
Write-Host “ttt3 - Sub Menu 3 - Option 3” Write-Host “tttQ — Återvänd till Huvudmenyn” $subMenu = Read-Host “t`tcommand to run?”
switch ($subMenu)
{
1
{
loadSubMenu1Option1

}
2
{
#loadSubMenu2
}
3
{
#loadSubMenu3
}
q
{
$loopSubMenu = $false
}
default
{
Write-Host -BackgroundColor Red -ForegroundColor White “FEL val för Kommando försök igen.”
sleep -Seconds 1
}
}
}
}

function loadSubMenu1Option1()
{

Repeat Code Block from mainMenuOption1. Continue nesting based on features/selections you want.

}

Start the Menu once loaded:

loadMainMenu

Extras:

if ($clearHost) {Clear-Host}
if ($exitSession) {Exit-PSSession};

3 Spice ups

hmm try this

https://community.spiceworks.com/scripts/show/4279-powershell-menu-and-selection

1 Spice up

Welcome

Then you should have seen how to post code.

If you post code, please use the ‘Insert Code’ button. Please and thank you!

192033ab-bb8f-4032-88a5-8e2313af0344-codebutton_small.png

  • Neally Bot