【问题标题】:PowerShell script execution within PHP在 PHP 中执行 PowerShell 脚本
【发布时间】:2012-08-19 03:22:46
【问题描述】:

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

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

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

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 只是挂起。有什么想法吗?

【问题讨论】:

  • 提示:在路径中使用正斜杠。 PHP 会为你自动翻译,然后你就不必加倍翻译了。

标签: php powershell iis-7


【解决方案1】:

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

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

【讨论】:

  • 我是我们推送的所有组策略的系统管理员,我们目前没有在我们的任何服务器上设置此设置。此外,当我运行“Get-ExecutionPolicy”时,它会显示我上次设置的任何值。
猜你喜欢
  • 2011-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 2012-09-18
  • 2012-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多