深入浅出Power Shell——cmd调用PowerShell脚本

我在访问ps1文件的时候,一定要注意访问路径中是否包含空格。

包含空格要用单引号''来处理。

 

PowerShell -command Set-ExecutionPolicy "Bypass"
set filepath= '%CD%\AppDeployment.ps1'
PowerShell -command "& %filepath%"
Pause

 

 

 

错误的写法:

PS C:\> C:\Documents and Settings\Mingle\My Documents\PS\test.ps1

The term 'C:\Documents' is not recognized as a cmdlet, function, operable progr
am, or script file. Verify the term and try again.
At line:1 char:13
+ C:\Documents  <<<< and Settings\Mingle\My Documents\PS\test.ps1

 

正确的写法:

powershell.exe -noexit & 'C:\Documents and Settings\Mingle\My Documents\PS\test.ps1'

posted @ 2013-04-17 12:55  风影极光  阅读(3104)  评论(0编辑  收藏  举报