Well… writing this kind of forced user interaction is generally frowned on whenever you can avoid it, but assuming that this is what you need, there’s only one bug that I see in your code right now:
default {"You have not selected a valid option"; $Is_Remote = ""; Is_Remote}
In your default block, you’re outputting the string “You have not selected a valid option” to the pipeline, then calling Is_Remote recursively (eventually returning “Yes” or “No”). If you look at the value of $Is_Remote after the function returns, you’ll find one instance of the string “You have not selected a valid option” for every bad option that the user entered, followed by the eventual “Yes” or “No”. Now, you could avoid polluting the pipeline with that message by making it a call to Write-Host instead of just outputting the string, but since you’re clearing the screen as soon as Is_Remote is called anyway, no one’s going to get a chance to read that “You have not selected a valid option” message anyway, so you may as well just get rid of it:
On a side note, this is not the greatest use of recursion. You could accomplish the same result with a loop, and not wind up consuming extra resources for the call stack (possibly resulting in whatever PowerShell’s equivalent of a stack overflow is.)
Function Is_Remote {
$RemoteMenuArray = ,@(1,"Yes")
$RemoteMenuArray +=,@(2,"No")
while ($true)
{
cls
Write-Host "————-"
foreach ($a in $RemoteMenuArray) {Write-Host $a}
Write-Host "————-"
$x = Read-Host "Is the user Remote?"
Switch ($x)
{
1 {return "Yes"}
2 {return "No"}
}
}
}