php - 使用php exec函数进行Powershell远程执行

标签 php powershell

我正在尝试使用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/

相关文章:

php - 通过 Enter 提交(具体提交 提交名称)

javascript - 如何将参数 lang 传递给另一个 url

email - 通过身份验证向多个收件人发送电子邮件

powershell - 将字符串参数发送到 Start-Job 脚本 block

powershell - 将 "-Filter"与变量一起使用

php - 从字符串中提取组

php - 对 api token 使用 Config 会出现错误 'URI must be a string or UriInterface' Laravel

php - Laravel 多对多不工作

powershell - 快速对包含大量日期的数组进行排序

PowerShell $_ 语法