I am a beginner in Powershell and I have a small problem.
I have 2 scripts (menu and submenu). I run script_A (menu) and when I select option 9 (exit) it works as expected. But when I run script_A and I choose option 1 (submenu), and then I choose option 9 (return to script_A) and again select 9 (exit), this message appears: invalid option.
Why? Can someone help me? scripts A and B are:
Script_A:
$resposta = $null
$vocetemcerteza = $null
$PSScriptRoot
$ScriptToRun1= $PSScriptRoot+"\DNSMenu.ps1"
function vocetemcerteza {
$vocetemcerteza = read-host "Do you have exit? (y/n)"
if ($vocetemcerteza -eq "y"){Exit}
elseif ($vocetemcerteza -eq "n"){mainmenu}
else {write-host -foregroundcolor red "Invalid Option."
vocetemcerteza
}
}
function mainmenu{
$vocetemcerteza = "n"
cls
echo " 1. DNS"
echo ""
echo " 9. Exit"
$resposta = read-host "Choose a option:"
if ($resposta -eq 1){&$ScriptToRun1}
if ($resposta -eq 9){vocetemcerteza}
else {echo ""
write-host -ForegroundColor magenta "Invalid Option."
sleep 1
cls
mainmenu
}
}
mainmenu
Script_B:
$ScriptToRun1= $PSScriptRoot+"\DNSemLoteMenu.ps1"
function mainmenu{
$vocetemcerteza = "n"
cls
echo ""
echo " 1. Create register"
echo ""
$resposta = read-host "Choose a option:"
if ($resposta -eq 1){&$ScriptToRun1}
if ($resposta -eq 9){mainmenu}
else {echo ""
write-host -ForegroundColor magenta "Invalid Option."
sleep 1
mainmenu
}
}
mainmenu