I am trying to validate a UNC path using a RegEx and having problems failing on disallowed characters. I can use this to validate one or more characters after \, and before an optional additional .
$fileSystemUNCOnly = '^\\\\.+(\\)?$'
$path = '\\Server'
CLS
if ($path -match $fileSystemUNCOnly) {
Write-Host 'Good'
} else {
Write-Host 'Bad'
}
However, if I try to fail on a disallowed character such as | and $path = '\\Server|'
, it still shows good.
$fileSystemUNCOnly = '^\\\\[^:\*\?\"<>\|]'
What am I doing wrong in the disallow?