If statement on Path variable – powershell – true/false test

Question:

Basically I want to do a check if a directory exists then run this section, if not exit.

The script I have is:

But it returns nothing.

Answer:

The error comes from the fact that the return value of Test-Path is a Boolean type.

Hence, don’t compare it to strings representation of Boolean but rather to the actual $false/$true values. Like so,

Also, note that here you could use an else statement here.

Alternatively, you could use the syntax proposed in @user9569124 answer,

Source:

If statement on Path variable – powershell – true/false test by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply