Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From the PowerShell prompt:


will run Paint. So will

Invoke-Expression -command "\Windows\system32\mspaint.exe"

but if there is a space in the path PowerShell spits the dummy e.g.

Invoke-Expression -command "\install\sub directory\test.bat"

Which complains:

The term '\install\sub' is not recognized as the name of a cmdlet, function, script file, or operable program.

What am I missing?

share|improve this question
For more on this topic, see this Powershell "gotcha"...… – Nathan Hartley Apr 21 '15 at 22:30
up vote 2 down vote accepted

According to this article on Technet, enclosing the path in double quotes is not enough.

The path that you are trying to use must have an & (ampersand) in front of the directory or it shall not work.

For example:

Invoke-Expression -command & "\install\sub directory\test.bat"
share|improve this answer
Either use Invoke-Expression or &, not both. – Richard Nov 23 '11 at 8:40
More specifically to use & with Invoke-Expression the & needs to be part of the command, something like: Invoke-Expression '& "\install\sub directory\test.bat"'. – Richard Nov 23 '11 at 8:47

The simplest way is to use the invoke operator:

&'String containing the path'

Note, to launch an executable Invoke-Expression is really the wrong cmdlet, better to use Start-Process.

share|improve this answer
Thanks for this answer. I will try Start-Process – John Hartley Nov 24 '11 at 22:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.