I am getting result if i use below in php exec
exec("powershell get-aduser '$user' -properties * -server '$domain.company.com'", $output, $return_code);
But not with pipe. For example this doesnt work.
exec("powershell get-aduser '$user' -properties * -server '$domain.company.com'|select cn", $output, $return_code);
If i hardcode user and domain, it works. for example this works.
exec('powershell "get-aduser xyz -properties * -server abc.company.com | select cn"', $output, $return_code);
I need to use variable for user and domain. currently it doesn't work for me with pipe. Can anyone help me on this.
Finally this worked for me. Thank you nogad. I have to use multiple domains based on the users input. so i didn't add company.com to $domain variable.
$cmd='powershell "get-aduser '.$user.' -properties * -server '.$domain.'.company.com | select -expand cn"';
exec($cmd, $output, $return_code);