Launching Files with Spaces

by May 27, 2009

What if you'd like to launch a file with spaces in its path? The first rule is that spaces are separators, so PowerShell would separate it at the spaces and break it up in several invalid paths, which is no good.

So whenever a path contains spaces, you need to quote it. Use single quotes unless you want to resolve variables that are part of your path name. Then, you should use double quotes.

This leads to another problem. Once quoted, PowerShell treats your command as a plain string and echoes it back to you. To invoke the string, add "&" or "." like this:

& "$env:programfilesInternet Exploreriexplore.exe"