by Andy Barber
4. August 2009 13:44
Taken from Dave Donaldson's blog at: http://arcware.net/running-a-powershell-script-with-a-space-in-the-path/
Like with any new technology, getting started with PowerShell was not without a few hiccups. One of the first issues I ran into was how to properly pass script locations to PowerShell so that it could actually run them.
It turns out that PowerShell is a bit finicky in how it locates the script to run. You basically have two options for getting PowerShell to find and run your scripts:
- Explicitly pass the full path of the script to PowerShell, or
- Add your script location to the PATH environment variable so that you can just pass the script name
As simple as those sound, there's still a catch: if the path to your script contains a space, PowerShell won't be able to find it and will throw an error, unless you use some special notation. For example, below I'm trying to run a PowerShell script where the path has a space in it:
Enclosing the path in quotes works with your basic cmd.exe, but not in PowerShell. To get this to work in PowerShell, you need to use notation that follows this format:
"& '[full path to script]'"
I told you the notation was special. So now I have this, which will run the script just fine:
And there you have it. You can bet I've filed this one away permanently.