问题
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