Executing Power Shell Scripts from Windows Shell

Executing Power Shell Scripts from Windows Shell

Post by Mugunt » Thu, 03 May 2007 18:31:44


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.
 
 
 

Executing Power Shell Scripts from Windows Shell

Post by UmljaF » Fri, 04 May 2007 00:16:01

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://www.yqcomputer.com/
PowerShell User Group: http://www.yqcomputer.com/

 
 
 

Executing Power Shell Scripts from Windows Shell

Post by Marcel J. » Fri, 04 May 2007 00:48:47

> My question is, even when the path is enclosed within double quotes,

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'
 
 
 

Executing Power Shell Scripts from Windows Shell

Post by Mugunt » Fri, 04 May 2007 12:37:06

On May 2, 8:48 pm, "Marcel J. Ortiz [MSFT]"




Thanks,
This is what I really needed...