Using a PowerShell command within PHP works until I do thisRSS

1 reply

Last post Aug 03, 2015 03:39 AM by lextm

  • Using a PowerShell command within PHP works until I do this

    Jul 24, 2015 09:11 AM|TomKaz|LINK

    In a PowerShell console a XenApp cmdlet works simply like this. I get all sessions for the designated user:

    Get-XASession | where {$_.accountname -LIKE "domain\JoeB"}

    In a PHP script this won't work however:

    <?php
    $my_array2 = array(); 
    exec('powershell.exe -command "Get-XASession | Select -Property accountname, logontime | where {$_.accountname -LIKE "domain\JoeB" }  " <NUL ', $my_array);`
    ?>

    As a result I get all sessions in the Citrix farm as the filter for accountname is not read in. It's seemingly a PHP issue wherein my inclusion of double quotes to define the value of accoutname are messing up the PHP. The command is being truncated prematurely is my guess.

    So next I tried this hoping to have those double quotes surrounding domain\joeb be escaped from the PHP:

    exec('powershell.exe -command "Get-XASession | Select -Property accountname, logontime | where {$_.accountname -LIKE '. "domain\JoeB" . '}  " <NUL ', $my_array);`

    But this is still not getting it . What is the correct PHP syntax please?


     

  • Re: Using a PowerShell command within PHP works until I do this

    Aug 03, 2015 03:39 AM|lextm|LINK

    https://blog.lextudio.com/2015/04/web-application-differences-in-visual-studio-and-iis/

    The executing account matters a lot for such a script.

    When running in PHP on IIS or any other web server, the executing account might not meet the requirements.

    Lex Li
    Affordable IIS Consulting Services at https://support.lextudio.com/services/consulting.html
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.