I am having this below simple code to display menu in a script
Write-Host "============= Main Category ================================="
Write-Host " '1' InfoBlox"
Write-Host " '2' Installation"
Write-Host " '3' Active Directory"
Write-Host " '4' LogInventory"
Write-Host " '5' Configuration"
Write-Host " '6' New Server Build CMDB Update "
Write-Host " '7' for Exit"
Write-Host "========================================================"
$choice = Read-Host "`nEnter Choice"
if($choice -eq '1')
{
#Menu for choice
cls
Write-Host "=============InfoBlox================================="
Write-Host " '1' Add CNAME record"
Write-Host " '2' Delete CNAME record"
Write-Host " '3' Add A-record and PTR record"
Write-Host " '4' Delete A-record and PTR record"
Write-Host " '5' for Main Menu"
Write-Host "========================================================"
$subchoice = Read-Host "`nEnter Choice"
#code here
if($subchoice -eq '5')
{
cls
Write-Host "============= Main Category ================================="
Write-Host " '1' InfoBlox"
Write-Host " '2' Installation"
Write-Host " '3' Active Directory"
Write-Host " '4' LogInventory"
Write-Host " '5' Configuration"
Write-Host " '6' New Server Build CMDB Update "
Write-Host " '7' for Exit"
Write-Host "========================================================"
$choice = Read-Host "`nEnter Choice"
}
if($choice -eq '2')
{
#code here
}
if($choice -eq '3')
{
#code here
}
Problem I am facing is when I am executing first time it is working fine. e.g. when I choose **1,2,3..**it is fine but when I am again going back from 3 to 1 as choice, the script is exiting and showing the powershell prompt.
Please let me know why it is happening. I may be not able to explain properly. please let me know if any question.