powershell - execute cmdlet remotely with php

…衆ロ難τιáo~ 提交于 2019-12-24 17:50:14

问题


I need to get status of service for simple monitoring tool. There is no problem to get status locally, but when I try to get status of service on remote computer like this:

<?php 
$output = shell_exec('powershell.exe "(get-service Webclient -computername server1).Status"');
echo "Webclient:  $output ";
?>

I get nothing. WinRM on server1 is set to receive requests and to allow remote access. The Get-Service on remote server1 works fine in console window.

This works (locally):

<?php 
$output = shell_exec('powershell.exe "(get-service Webclient).Status"');
echo "Webclient:  $output ";
?>

I've tried to change shell_exec to exec or system, but with no effect. Thank you.


回答1:


I am currently trying to do the same thing, and this code is very helpful. Thank you. Looking at your problem one though that came to my mind it could be that you need to allow scripts to be run on the remote server.



来源:https://stackoverflow.com/questions/14855329/powershell-execute-cmdlet-remotely-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!