I'm attempting to query an Exchange server using a powershell script executed by PHP and it doesn't seem to be working. The command I'm attempting to run is:
powershell "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010";"Get-CASMailbox -Identity user@example.com | fl ActiveSyncEnabled"
If I type that directly into the command prompt, it executes correctly and returns:
ActiveSyncEnabled : True
When I try it in PHP:
$output=shell_exec('powershell "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010";"Get-CASMailbox -Identity user@example.org | fl ActiveSyncEnabled"');
I get nothing. $output is set but blank. If I add "> output.txt" to the end, I get a blank text file. I'm able to run other, simpler powershell commands successfully via PHP, but not this one. The Apache service is running as the same user as when I successfully executed the script via the command prompt.
Any ideas?
I'm running:
You may try adding 2>&1
at the end of the command, eg:
$output=shell_exec('powershell "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010";"Get-CASMailbox -Identity user@example.org | fl ActiveSyncEnabled" 2>&1');
Sometimes, a line break at the beginning of the powershell output seems to prevent shell_exec
printing anything else.
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.