Remove Illegal characters from filename

16/11/2012 17:13

$file = "this*file\\i?.txt"
$file
$pattern = "[{0}]" -f ([Regex]::Escape([String][System.IO.Path]::GetInvalidFileNameChars()))
$newfile = [Regex]::Replace($file, $pattern, '-')
$newfile