While raw .NET calls provides you with granular control over how to validate paths and file names, there is a cmdlet called Test-Path for simple purposes. Its primary purpose is to validate whether a file or path exists. When adding the -isValid parameter though, the cmdlet will validate the path and return $false if it found illegal characters:
$path = Read-Host 'Enter a path'
} until (Test-Path -isvalid $path)
Jun 17 2009, 08:00 AM