I have written a Switch statement where, if the user inputs anything other than Y or N, the script should keep prompting until they enter either one of those letters.
$Prompt = Read-host "Should I display the file contents c:\test for you? (Y | N)"
Switch ($Prompt)
{
Y {Get-ChildItem c:\test}
N {Write-Host "User canceled the request"}
Default {$Prompt = read-host "Would you like to remove C:\SIN_Store?"}
}
What happens now, however, is that when the user inputs anything other than Y or N, they get prompted again. But when they type any letter the second time, the script just exits. It doesn’t ask the user for their input anymore. Is it possible to accomplish this using Switch?
I don’t understand what you are trying to do in the default in your code, but as per your question, you want to put it in a loop:
Powershell way of doing this: