在 PHP 中执行 PowerShell 脚本


PowerShell script execution within PHP

我正在尝试通过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 执行策略设置为"无限制"和"远程签名",但它无法纠正此问题。如果我从 PowerShell 命令行调用它,并且从 Windows 中的命令提示符调用它,则脚本运行良好。

我也尝试了以下方法:

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

而IIS只是挂起。有什么想法吗?

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

编辑:实际上,根本原因要简单得多。 您没有用结束引号"结束字符串。 那肯定会挂IIS。