the desired output would be to repeat the question until either "Y" or "N" is selected.
$msg = 'Does this Share contain Sensitive Data? [Y/N]'
do {
$response = Read-Host -Prompt $msg
if ($response -eq 'n') {
$sdata = "No"
}
if ($response -eq 'y') {
$sdata = "(Sensitive)"
}
} until ($response -ne '$null')
However if I enter anything else it will still continue to run the script. I have this working on other scripts so I am unsure of why its not working now.
Thanks as always!
So you want to repeat the prompt until someone enters a valid value - either
yorn.You can either use the
-oroperator:Since you're testing the same variable for one of multiple possible values, you could also use the reverse containment operator
-into test if the input was part of the set of valid values:... or, if you want a "cleaner" condition expression, use a variable to keep track of whether a valid value has been entered: