In PowerShell, the syntax for if
looks like this:
if (<test1>) {<statement list 1>} [elseif (<test2>) {<statement list 2>}] [else {<statement list 3>}]
Another syntax rule: for subexpressions, you need to use parentheses as follows:
write-output (get-date)
Thus, if these two rules were combined, I would expect that the test for some path should be written with two sets of parentheses, such as:
if ((Test-Path ...)) {
However, this also works:
if (Test-Path ...) {
and just for completeness, this one doesn't work :
if (!Test-Path ...) {
(here you will need to copy the subexpression in brackets, as usual).
Can someone explain the syntax rules that apply here, and how is it that I can use the IF test with only one bracket? Is this some kind of PowerShell magic, or do I not understand the basic syntax rules?
Borek source share