【问题标题】:Powershell remote execution with php exec function使用 php exec 函数执行 Powershell 远程执行
【发布时间】:2015-09-19 00:57:12
【问题描述】:

我正在尝试使用 php 脚本在远程计算机上运行 Powershell 命令。

执行本地 Powershell 脚本没有问题。比如我成功执行了以下代码:

exec("Powershell -Command C:\wamp\www\pstest.ps1", $output, $return_var);

输出:“Hello world”,返回码:0

当我使用命令提示符执行以下命令时,我没有问题。

Powershell -Command Invoke-Command -ComputerName computer.servername.local C:\wamp\www\pstest.ps1

输出:“Hello world”,返回码:0

但是,当我尝试从我的 php 脚本中执行相同的代码时,它会失败。

exec("Powershell -Command Invoke-Command -ComputerName computer.servername.local C:\wamp\www\pstest.ps1", $output, $return_var);

输出:“”,返回码:1

【问题讨论】:

    标签: php powershell


    【解决方案1】:

    确保运行服务的帐户在该目标系统上具有管理员权限。如果这是家里的个人项目,这应该没问题。如果这是在公司系统上,您可能需要重新考虑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 2022-10-12
      • 2012-08-18
      • 2023-03-26
      相关资源
      最近更新 更多