‘unexpected token’ in PowerShell when fully pathing executable

Question:

Just trying to better understand why the second item below does not work. The first item is simple, the second seems clearer, the third seems unintuitive.

Answer:

That’s because this is also considered a parse error:

Whereas this parses correctly as you have found:

That resolves to a valid string but as you have already noticed, a string doesn’t execute. You have to use the call operator & to invoke the command that is named by the string that follows.

Source:

‘unexpected token’ in PowerShell when fully pathing executable by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply