PowerShell script cannot be ran outside of Console if path contains spaces
Votes from Connect: 11
Original Date Submitted: 5/29/2013 2:52:43 AM
Site Name: PowerShell
Feedback ID: 788806
Frequency: Always Happens
Regression: Yes, this happens in all previous versions
If you try and run a PowerShell script from File Explorer (e.g. Windows Explorer) by double clicking on it, or from the context menu using Open With -> Windows PowerShell the script will not run; instead the PowerShell console will display an error that the given file path is not valid, since only the first portion (up to the first space) of the script file path is passed to powershell.exe. The solution is a simple registry tweak to enclose the path passed to the powershell executable in double quotes.
Essentially you just need to change the key:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "& "%1""
I explain this problem and the registry workaround in more detail on my blog at http://blog.danskingdom.com/fix-problem-where-windows-powershell-cannot-run-script-whose-path-contains-spaces/.
I found a related bug report (https://connect.microsoft.com/PowerShell/feedback/details/718060/power-shell-scripts-fail-at-startup-if-file-path-has-a-space-in-it) which seems to be a specific instance of this more general problem.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 788806 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=788806).
1 - Create a powershell script with spaces in the file name or the directory that the script is in.
2 - Try running the powershell script by double clicking on it, or right-clicking it and choosing Open With -> Windows PowerShell.
The script should run, but instead an error is thrown that it cannot find the script.
Internal BugId: 4225