我試圖從PHP執行powershell腳本,但它似乎不工作。從php執行Powershell腳本
腳本'newEvent.ps1'在Exchange服務器上創建一個事件。
$psPath = "powershell.exe";
$psDIR = "C:\\wamp\\www\\ant\\assets\\ps\\";
$psScript = "newEvent.ps1";
$runScript = $psDIR. $psScript;
$runCMD = $psPath." ".$runScript." 2>&1";
echo "\$psPath $psPath <br>";
echo "\$psDIR $psDIR <br>";
echo "\$psScript $psScript <br>";
echo "\$runScript $runScript <br>";
echo "\$runCMD $runCMD <br>";
exec($runCMD,$out,$ret);
echo "<pre>";
print_r($out);
print_r($ret);
echo "</pre>";
它輸出:
$psPath powershell.exe
$psDIR C:\wamp\www\ant\assets\ps\
$psScript newEvent.ps1
$runScript C:\wamp\www\ant\assets\ps\newEvent.ps1
$runCMD powershell.exe C:\wamp\www\ant\assets\ps\newEvent.ps1 2>&1
Array
(
[0] => File C:\wamp\www\ant\assets\ps\newEvent.ps1 cannot be loaded because the execut
[1] => ion of scripts is disabled on this system. Please see "get-help about_signing"
[2] => for more details.
[3] => At line:1 char:39
[4] => + C:\wamp\www\ant\assets\ps\newEvent.ps1 <<<<
[5] => + CategoryInfo : NotSpecified: (:) [], PSSecurityException
[6] => + FullyQualifiedErrorId : RuntimeException
[7] =>
)
如果我運行命令行powershell.exe C:\wamp\www\ant\assets\ps\newEvent.ps1
,它工作正常。
這是我第一次嘗試類似這樣的事情。我跑了Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
但它仍然給我同樣的錯誤。 其實我跑Set-ExecutionPolicy unristricted
,但還是一樣。
看看你正在運行的命令行。 – 2011-03-15 20:17:11
確保進入32位和64位實例並設置執行策略,然後重試。 - > Set-ExecutionPolicy無限制 – 2012-06-04 13:18:41