So I'm trying to check if the Path is available. I do this with the Test-Path
It looks like this:
$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"
}
So what am I doing wrong if the error looks like this:
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`
You wan't to compare the result of the Test-Path cmdlet so you need to use parentheses otherwise the -eq parameter gets passed to the Test-Path cmdlet and thats the reason why you get the error.
I would use the -not operator since I found it more readable. Example:
if(-not (Test-Path $c)) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With