I'm having an issue with PowerShell when invoking an exe at a path containing spaces.
cd C:\Windows Services
invoke-expression "C:\Windows Services\MyService.exe"`
Output:
The term 'C:\Windows' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
It seems to be splitting on the space between 'Windows' and 'Services'. How can I get around this problem?
&, the call operator, to invoke commands whose names or paths are stored in quoted strings and/or are referenced via variables, as in the accepted answer.Invoke-Expressionis not only the wrong tool to use in this particular case, it should generally be avoided.