【发布时间】:2011-07-16 02:18:34
【问题描述】:
我正在尝试从 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,但还是一样。
【问题讨论】:
-
看看你正在运行的命令行。
-
确保同时进入 32 位和 64 位实例并设置执行策略,然后重试。 -> Set-ExecutionPolicy Unrestricted
标签: php powershell exchange-server shell-exec