How do I run a Powershell script from PHP

2019-03-05 05:04发布

问题:

I wrote one line of powershell script that downloads DHCP lease data. when i run it from powershell it works (exports the data into a csv file). but if i run the same code from php it exports an empty csv file. The powershell script and php code id below.

DhcpServerv4Lease -ComputerName "HAP2000-11" -ScopeId 10.10.10.0 | Select-Object -Property IPAddress, Clientid, Description, HostName | Export-Csv -Path ("C:\wamp64\www\new.csv") 

php code

<?php
if(isset($_POST['updateDHCP'])){
        shell_exec('powershell.exe -command C:\wamp64\www\DhcpLeasesExport1.ps1');
    }
?>