带有php exec函数的Powershell远程执行


Powershell remote execution with php exec function

我正试图用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

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