PHP Powershell command

前端 未结 2 1083
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 17:56

Trying to run the following command in php to run powershell command...

the following works:

$output = shell_exec(escapeshellcmd(\'powershell get-ser         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 18:14

    'powershell get-service | group-object'
    

    will be interpreted as

    1. run powershell and pass it get-service as an argument
    2. then pipe the output of powershell to group_object (i.e. not the output of get-service)

    What you want is for powershell to see get-service | group-object as it's argument, so you have to enclose that in quotes, like this.

     $output = shell_exec('powershell "get-service | group-object"');
    

提交回复
热议问题