The script below reads an input file from the command line and then checks if it exists. If not found it keeps prompting for a correct filename.
FileToRead = Read-Host "Please enter the filename"
$Found = "N"
Do {
if (Test-Path -LiteralPath $FileToRead) {
"[INFO] File found: $FileToRead. Continuing..."; echo "`n"; $Found = "Y"
}
else {
"[ERROR] Cannot find $FileToRead. Please try again."; echo "`n"
$FileToRead = Read-Host "Please enter the filename or abort with CTRL-C"
}
} Until ($Found -eq "Y")