Many people who have worked with PowerShell have reached this problem.

You have a exe file in a folder that includes spaces. (fx. "C:\Program Files\")

This exe file needs to be called with an argument that starts with "-".

at the same time , you need to call it from another folder.


In this example, I was installing a java web service and application.

I needed to run the java.exe to import at .jar file.

The jar file was in  "C:\Jboss\Libraries\" but the java.exe needed to import it was in

"C:\Program Files\Java\jdk1.6.0._04\bin\"

at first I didn't notice the space, and ran the command:



This ofcause fails, since "C:\Program Files" has a space. Most people have seen this a lot of time, since it it easy to forget to put quotationmarks around the path.

So I tried that instead:


Unfortunately this does not work in PowerShell! I did work in the old command prompt, but in PowerShell the command "-jar" after a text string has a comparison function instead.

This causes PowerShell to fail cause I cannot compare the 2 text string I typed, and at the same time, no default comparison operators are called -jar.

So, I tried to only put the path inside the quotation marks, but no luck



Of cause, like in most other PowerShell Stuff, there is different ways to makes this work.

One way is it not use the quotes, and instead put the escape char `before all spaces like this:


Or you can put & in front of the command, to make sure that PowerShell executes the text string, instead of trying to compare it.



Í might be able to find different ways to do it, or smarter way to do it, but i 'll thin k I'll stay with these.

But please do not hesitate to comments with different solutions, if you have a reason of why it is smarter/easier.