我正在尝试使用php脚本在远程计算机上运行Powershell命令。
我毫不费力地执行本地Powershell脚本。例如,我成功执行了以下代码:
exec("Powershell -Command C:\wamp\www\pstest.ps1", $output, $return_var);
Output: "Hello world", Return code: 0
当我通过命令提示符执行以下命令时,我没有任何问题。
Powershell -Command Invoke-Command -ComputerName computer.servername.local C:\wamp\www\pstest.ps1
Output: "Hello world", Return code: 0
但是,当我尝试从我的PHP脚本中执行相同的代码时,它将失败。
exec("Powershell -Command Invoke-Command -ComputerName computer.servername.local C:\wamp\www\pstest.ps1", $output, $return_var);
Output: "", Return code: 1
最佳答案
确保运行该服务的帐户对该目标系统具有管理员权限。如果这是在家中的个人项目,那应该很好。如果这是在公司系统上,则可能需要重新考虑。
关于php - 使用php exec函数进行Powershell远程执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31168593/