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 - can't run script from folder containing spaces

Reply
 
Old 03-07-2007   #1 (permalink)
delta99


 
 

can't run script from folder containing spaces

I am trying to run a script from a command prompt that is in folder
containing spaces but I get the following error:

C:\Temp\a b>.\test.ps1
The term 'C:\Temp\a' is not recognized as a cmdlet, function, operable
program,
or script file. Verify the term and try again.
At line:1 char:10
+ C:\Temp\a <<<< b\test.ps1

It runs fine when there are no spaces in the path (e.g. I run it from
c:\temp).

I have also tried a number of variations around the full path, e.g.

C:\Temp\a b>"c:\temp\a b\test.ps1"

to no avail.

I am sure this is something really simple but I can't see it!

Many thanks!


My System SpecsSystem Spec
Old 03-07-2007   #2 (permalink)
Brandon Shell


 
 

Re: can't run script from folder containing spaces

If you use tab complete in powershell it will make it look like

PS> & 'c:\temp\a b\test.ps1'

You can also do
PS> .\test.ps1
or
PS> invoke-expression "C:\temp\'a b'\test.ps1"
or
PS> c:\temp\'a b'\test.ps1

"delta99" <delta99@discussions.microsoft.com> wrote in message
news:4B851FAE-E968-464F-8161-A3CAE633B1F1@microsoft.com...
>I am trying to run a script from a command prompt that is in folder
> containing spaces but I get the following error:
>
> C:\Temp\a b>.\test.ps1
> The term 'C:\Temp\a' is not recognized as a cmdlet, function, operable
> program,
> or script file. Verify the term and try again.
> At line:1 char:10
> + C:\Temp\a <<<< b\test.ps1
>
> It runs fine when there are no spaces in the path (e.g. I run it from
> c:\temp).
>
> I have also tried a number of variations around the full path, e.g.
>
> C:\Temp\a b>"c:\temp\a b\test.ps1"
>
> to no avail.
>
> I am sure this is something really simple but I can't see it!
>
> Many thanks!
>


My System SpecsSystem Spec
Old 03-07-2007   #3 (permalink)
delta99


 
 

Re: can't run script from folder containing spaces

Hi Brandon,

Thanks for your suggestions - they work fine from a powershell window!

However, I am trying to run the script from a DOS command prompt (or by
double-clicking on the ps1 script in explorer) - if the path contains no
spaces the script executes, otherwise it doesn't ...

"Brandon Shell" wrote:

> If you use tab complete in powershell it will make it look like
>
> PS> & 'c:\temp\a b\test.ps1'
>
> You can also do
> PS> .\test.ps1
> or
> PS> invoke-expression "C:\temp\'a b'\test.ps1"
> or
> PS> c:\temp\'a b'\test.ps1
>
> "delta99" <delta99@discussions.microsoft.com> wrote in message
> news:4B851FAE-E968-464F-8161-A3CAE633B1F1@microsoft.com...
> >I am trying to run a script from a command prompt that is in folder
> > containing spaces but I get the following error:
> >
> > C:\Temp\a b>.\test.ps1
> > The term 'C:\Temp\a' is not recognized as a cmdlet, function, operable
> > program,
> > or script file. Verify the term and try again.
> > At line:1 char:10
> > + C:\Temp\a <<<< b\test.ps1
> >
> > It runs fine when there are no spaces in the path (e.g. I run it from
> > c:\temp).
> >
> > I have also tried a number of variations around the full path, e.g.
> >
> > C:\Temp\a b>"c:\temp\a b\test.ps1"
> >
> > to no avail.
> >
> > I am sure this is something really simple but I can't see it!
> >
> > Many thanks!
> >

>
>

My System SpecsSystem Spec
Old 03-07-2007   #4 (permalink)
Brandon Shell


 
 

Re: can't run script from folder containing spaces

This should work
powershell "c:\temp\'a b'\test.ps1"

By default .ps1 are associated to notepad. This is for security reasons.
Unless you changed that I dont expect the clicking to work.

"delta99" <delta99@discussions.microsoft.com> wrote in message
news:9755DEA8-EA35-4F19-8D08-A80E1E7E9776@microsoft.com...
> Hi Brandon,
>
> Thanks for your suggestions - they work fine from a powershell window!
>
> However, I am trying to run the script from a DOS command prompt (or by
> double-clicking on the ps1 script in explorer) - if the path contains no
> spaces the script executes, otherwise it doesn't ...
>
> "Brandon Shell" wrote:
>
>> If you use tab complete in powershell it will make it look like
>>
>> PS> & 'c:\temp\a b\test.ps1'
>>
>> You can also do
>> PS> .\test.ps1
>> or
>> PS> invoke-expression "C:\temp\'a b'\test.ps1"
>> or
>> PS> c:\temp\'a b'\test.ps1
>>
>> "delta99" <delta99@discussions.microsoft.com> wrote in message
>> news:4B851FAE-E968-464F-8161-A3CAE633B1F1@microsoft.com...
>> >I am trying to run a script from a command prompt that is in folder
>> > containing spaces but I get the following error:
>> >
>> > C:\Temp\a b>.\test.ps1
>> > The term 'C:\Temp\a' is not recognized as a cmdlet, function, operable
>> > program,
>> > or script file. Verify the term and try again.
>> > At line:1 char:10
>> > + C:\Temp\a <<<< b\test.ps1
>> >
>> > It runs fine when there are no spaces in the path (e.g. I run it from
>> > c:\temp).
>> >
>> > I have also tried a number of variations around the full path, e.g.
>> >
>> > C:\Temp\a b>"c:\temp\a b\test.ps1"
>> >
>> > to no avail.
>> >
>> > I am sure this is something really simple but I can't see it!
>> >
>> > Many thanks!
>> >

>>
>>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Spaces in script path PowerShell
VBS script with spaces in executable path VB Script
Re: VB Script Code to get alert when a folder get changed in intranet FTP Folder VB Script
Passing parameters to PS script and escaping spaces PowerShell
script with spaces in the path 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