PHP中的PowerShell脚本执行

时间:2012-08-19 03:22:46

标签: php powershell iis-7

我正在尝试通过php运行一个PowerShell脚本。

system("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -InputFormat none -File AD_Account_Automation.ps1);

当我运行php脚本时,它会在Web浏览器中返回以下错误:

File C:\inetpub\wwwroot\Test_Automation.ps1 can not be loaded. The file C:\inetpub\wwwroot\Test_Automation.ps1 is not digitally signed. The script will not execute on the sys tem. Please see "get-help about_signing" for more details.. + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE xception + FullyQualifiedErrorId : RuntimeException

我已将PowerShell执行策略设置为Unrestricted和RemoteSigned,并且它没有解决问题。如果我从PowerShell命令行调用它并且从Windows中的命令提示符调用它,则脚本运行正常。

我也尝试了以下内容:

exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy RemoteSigned -File C:\\inetpub\\wwwroot\\AD_Account_Automation.ps1 < NUL");

IIS刚刚挂起。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

几乎可以肯定,您的托管环境不允许这样做。 ActiveDirectory GroupPolicy会覆盖数字签名。个唱。是的,我知道,它很糟糕,但它有充分的理由。联系您的托管服务提供商以检查这是否是根本原因。

编辑:实际上,根本原因要简单得多。你没有用一个结尾引号关闭字符串“。这肯定会挂起IIS。