I am accepting arguments to a script file for ServerName and Share. I want to make sure that the user does not add any leading or trailing forward slashes or backslashes.
Currently, I am doing this...
function validateServerShare($a_server, $a_share)
{
$a_server = $a_server -replace'\\',''
$a_server = $a_server -replace'/',''
$a_share = $a_share -replace'\\',''
$a_share = $a_share -replace'/',''
$Path = "\\$a_server\$a_share"
if(-not (Test-Path $Path))
{
haltError
}
return $Path
}
But I do not like the way I have to have multiple -replace lines. Is there a cleaner way or simpler way to strip forward and back slashes from a string, if they exist?
Thanks in advance for any help you can offer.