简体   繁体   中英

powershell - execute cmdlet remotely with php

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM