My Tech Tips


PowerShell, scripts and spaces in paths

, posted: 7-Aug-2009 21:12

Easy.  Just need to remember this one for next time

c:\windows\system32\windowspowershell\v1.0\powershell.exe "& 'c:\my dir with spaces\pstest.ps1' 'arg' 'arg' 'arg' "

Remember to open/close with double quote and use single quotes.
If you need to supply the quotes, remember it's 3 to escape for a single one!





Comment by EBGreen, on 9-Aug-2009 05:46

I'm not positive that I understand what you mean by this:

"If you need to supply the quotes, remember it's 3 to escape for a single one!"


But if you mean that you want to be able to have a double quote show up in a double quoted string, then using 3 quotes is the VBScript way. The Pwershell way is to use ` to escape the quote. As an example:

"There are `"quotes`" in this string"

[Hadders]
I've found the single quotes easier to work with in this situation. This example is for when you're invoking a PS script from a command prompt too.
So to add the single quotes to the string, you need 3, eg. '''arg'''


Add a comment

Please note: comments that are inappropriate or promotional in nature will be deleted. E-mail addresses are not displayed, but you must enter a valid e-mail address to confirm your comments.

Are you a registered Geekzone user? Login to have the fields below automatically filled in for you and to enable links in comments. If you have (or qualify to have) a Geekzone Blog then your comment will be automatically confirmed and placed in the moderation queue for the blog owner's approval.

Your name:

Your e-mail:

Your webpage:

Music









Books



Sites

Anandtech
Astronomy Picture of the Day
BBC News
Blue's News
DailyTech
Gizmodo Australia
IMDb
O'Reilly Books Online
Perth Current Weather
Perth Forecast
Perth IT Bloggers
Slashdot
Slashdot (games)
Stuff News
TV.com
WA News