This is not much but useful tip. Sometimes, while trying to read input from the user, you would want the response in yes/no (or y/n for that matter). You would not want users trying to enter anything or pressing any key by mistake which is mistaken for either yes/no. For this, we can use below specified simple code:
$YesOrNo = Read-Host "Please enter your response (y/n)" while("y","n" -notcontains $YesOrNo ) { $YesOrNo = Read-Host "Please enter your response (y/n)" }
Above example can also be modified to get limited set of choices from users.
Or even better:
do {
$YesOrNo = Read-Host “Please enter your response (y/n)”
} while (“y”,”n” -notcontains $YesOrNo)
LikeLike