所以我试图检查路径是否可用。我使用测试路径
看起来像这样:
$c="C:\"
$d="D:\"
$e="E:\"
if(Test-Path $c -eq "False"){
}
elseif(Test-Path $d -eq "False"){
}
elseif(Test-Path $e -eq "False"){
}
else{
"The File doesn't exist"
}
因此,如果错误如下所示,我该怎么办:
Test-Path : A parameter cannot be found that matches parameter name 'eq'.
At C:\Users\boriv\Desktop\ps\Unbenannt1.ps1:23 char:17
+ If(Test-Path $c -eq "False"){
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Test-Path], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.TestPathCommand`
最佳答案
您将无法比较Test-Path
cmdlet的结果,因此您需要使用括号,否则-eq
参数将传递给Test-Path
cmdlet,这就是您得到错误的原因。
我会使用-not
运算符,因为我发现它更具可读性。例:
if(-not (Test-Path $c)) {
}