Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - running script with blank space in path

Reply
 
Old 06-20-2008   #1 (permalink)
tomek


 
 

running script with blank space in path

Hi,

I'm trying tu run script from outside of PowerShell. The file is in a
folder with blank space.
I tried many things - using " or ' or ampersand in the beginning - but
either way I get an error

(powershell.exe "c:\my scripts\test.ps1"
The term 'c:\my' is not recognized as a cmdlet, function, operable
program, or
script file. Verify the term and try again.
At line:1 char:6
+ c:\my <<<< scripts\test.ps1)

or when I use ampersand
(powershell.exe -noexit &'c:\my scripts\test.ps1')
I enter PowerShell Console and the script is not executed.

I found this info on ampersand on:
http://www.microsoft.com/technet/scr...anual/run.mspx
but it doesn't seem to be working. Any ideas?
Tomek

My System SpecsSystem Spec
Old 06-20-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: running script with blank space in path

tomek wrote:
Quote:

> Hi,
>
> I'm trying tu run script from outside of PowerShell. The file is in a
> folder with blank space.
> I tried many things - using " or ' or ampersand in the beginning - but
> either way I get an error
>
> (powershell.exe "c:\my scripts\test.ps1"
> The term 'c:\my' is not recognized as a cmdlet, function, operable
> program, or
> script file. Verify the term and try again.
> At line:1 char:6
> + c:\my <<<< scripts\test.ps1)
>
> or when I use ampersand
> (powershell.exe -noexit &'c:\my scripts\test.ps1')
> I enter PowerShell Console and the script is not executed.
>
> I found this info on ampersand on:
> http://www.microsoft.com/technet/scr...anual/run.mspx
> but it doesn't seem to be working. Any ideas?
> Tomek
Try this as one possible way:

powershell.exe -command "&{& 'C:\some space\test.ps1'}

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 07-23-2008   #3 (permalink)
shannon searcy


 
 

Fix

As the example that follows shows you will have to use a back-tick to escape the space in your file path.

powershell.exe -noexit (&"d:\labs\new` folder\fixeddrivedata.ps1")
My System SpecsSystem Spec
Old 07-23-2008   #4 (permalink)
Shay Levy [MVP]


 
 

Re: Fix


You can try this too:


powershell.exe -noexit (& "'D:\Scripts\temp\New Folder\noexit.ps1'")

-or-

powershell.exe -noexit "& 'D:\Scripts\temp\New Folder\noexit.ps1'"




---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic



ss> As the example that follows shows you will have to use a back-tick
ss> to escape the space in your file path.
ss>
ss> powershell.exe -noexit (&"d:\labs\new` folder\fixeddrivedata.ps1")
ss>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Script Error with Path....ODD PowerShell
Pls doc how to execute an app that has embbedded space in its path PowerShell
script with spaces in the path PowerShell
How do I add to my PATH in a script? PowerShell
how to get path and name of the active Script PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46