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 - Executing Power Shell Scripts from Windows Shell

Reply
 
Old 05-02-2007   #1 (permalink)
Mugunth


 
 

Executing Power Shell Scripts from Windows Shell

Typing
powershell "D:\PowerShell Examples\TempScript.ps1"
on the cmd prompt, gives an error that,
The term 'D:\PowerShell' is not recognized as a cmdlet, function,
operable program, or script file. Verify the term and try again.
I understood that, it was because of the space.
So I removed the space and tried again and the script executed
successfully.

However,
typing
type "D:\PowerShell Examples\TempScript.ps1"
on the cmd prompt works fine.

My question is, even when the path is enclosed within double quotes,
why does powershell not recogonize the entire path and one single
argument?

Any help would be appreciated.


My System SpecsSystem Spec
Old 05-02-2007   #2 (permalink)
RichS


 
 

RE: Executing Power Shell Scripts from Windows Shell

Another couple of alternatives to running scripts with spaces in the path

c:\scripts\"test two"\test.ps1

will work. As will

$a = "c:\scripts\test two\test.ps1"
&$a

When the whole path is in quotes powershell will recognise it as a string.
So you either put part of the path in quotes or execute the command within
the string

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Mugunth" wrote:

> Typing
> powershell "D:\PowerShell Examples\TempScript.ps1"
> on the cmd prompt, gives an error that,
> The term 'D:\PowerShell' is not recognized as a cmdlet, function,
> operable program, or script file. Verify the term and try again.
> I understood that, it was because of the space.
> So I removed the space and tried again and the script executed
> successfully.
>
> However,
> typing
> type "D:\PowerShell Examples\TempScript.ps1"
> on the cmd prompt works fine.
>
> My question is, even when the path is enclosed within double quotes,
> why does powershell not recogonize the entire path and one single
> argument?
>
> Any help would be appreciated.
>
>

My System SpecsSystem Spec
Old 05-02-2007   #3 (permalink)
Marcel J. Ortiz [MSFT]


 
 

Re: Executing Power Shell Scripts from Windows Shell

> My question is, even when the path is enclosed within double quotes,
> why does powershell not recogonize the entire path and one single
> argument?


Its because powershell doesn't get the double quotes. cmd.exe will strip
the double quotes. Try something like this:

powershell "& 'd:\foo bar\script.ps1' "

cmd will strip the double quotes and powershell will run:
& 'd:\foo bar\script.ps1'



"Mugunth" <mugunth.kumar@gmail.com> wrote in message
news:1178098304.162166.326700@l77g2000hsb.googlegroups.com...
> Typing
> powershell "D:\PowerShell Examples\TempScript.ps1"
> on the cmd prompt, gives an error that,
> The term 'D:\PowerShell' is not recognized as a cmdlet, function,
> operable program, or script file. Verify the term and try again.
> I understood that, it was because of the space.
> So I removed the space and tried again and the script executed
> successfully.
>
> However,
> typing
> type "D:\PowerShell Examples\TempScript.ps1"
> on the cmd prompt works fine.
>
> My question is, even when the path is enclosed within double quotes,
> why does powershell not recogonize the entire path and one single
> argument?
>
> Any help would be appreciated.
>


My System SpecsSystem Spec
Old 05-02-2007   #4 (permalink)
Mugunth


 
 

Re: Executing Power Shell Scripts from Windows Shell

On May 2, 8:48 pm, "Marcel J. Ortiz [MSFT]"
<mos...@online.microsoft.com> wrote:
> > My question is, even when the path is enclosed within double quotes,
> > why does powershell not recogonize the entire path and one single
> > argument?

>
> Its because powershell doesn't get the double quotes. cmd.exe will strip
> the double quotes. Try something like this:
>
> powershell "& 'd:\foo bar\script.ps1' "
>
> cmd will strip the double quotes and powershell will run:
> & 'd:\foo bar\script.ps1'
>
> "Mugunth" <mugunth.ku...@gmail.com> wrote in message
>
> news:1178098304.162166.326700@l77g2000hsb.googlegroups.com...
>
> > Typing
> > powershell "D:\PowerShell Examples\TempScript.ps1"
> > on the cmd prompt, gives an error that,
> > The term 'D:\PowerShell' is not recognized as a cmdlet, function,
> > operable program, or script file. Verify the term and try again.
> > I understood that, it was because of the space.
> > So I removed the space and tried again and the script executed
> > successfully.

>
> > However,
> > typing
> > type "D:\PowerShell Examples\TempScript.ps1"
> > on the cmd prompt works fine.

>
> > My question is, even when the path is enclosed within double quotes,
> > why does powershell not recogonize the entire path and one single
> > argument?

>
> > Any help would be appreciated.


Thanks,
This is what I really needed...

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can parent shell monitor run/crash status of Child shell/exe ? PowerShell
Executing secondary command in shell.run VB Script
How to enable Power shell scripts PowerShell
Windows Command (Power Shell) does not work in Vista v5728 Vista General


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