Note:
Note that prefixing an executable path with .\
(which refers to a file in the current directory) if that path is a full (absolute) path (as in your 2nd attempt.,
.\"C:\Program Files\Notepad++\notepad++.exe"
) is both logically pointless and fails in practice.
If Notepad++.exe
is in one of the directories listed in the $env:PATH
environment variable:
# Note: NO ".\" prefix, which is only needed to invoke an executable
# located in the *current directory*.
Notepad++.exe $TargetFile
If you need to reference it by its full path, there is no need to use Set-Location
followed by a .\
-prefixed invocation (unless you truly need the working directory to be Notepad++'s installation directory).
To call it by its full path directly, use &
, the call operator:
& "C:\Program Files\Notepad++\notepad++.exe" $TargetFile
Note that &
is required in this case, because your executable path is quoted, of necessity, due to containing embedded spaces. As the first command above shows, &
is optional if the executable name or path is unquoted (and contains no variable references) - see this answer for more information.