In a PowerShell console a XenApp cmdlet works simply like this. I get all sessions for the designated Citrix user:
[CODE]Get-XASession | where {$_.accountname -LIKE “domainJoeB”}
That’s simply pure PowerShell.. Now I am able to run PowerShell commands in a PHP script like this:
[CODE]<?php
$my_array2 = array();
exec(‘powershell.exe -command “Get-XASession | Select -Property accountname, logontime ” <NUL ‘, $my_array);`
?>
Simple stuff, but having all Citrix sessions sent to a web page is not very useful. Rather I want to filter the User ID in PHP as I did in the first code example.
However I can’t do this:
[CODE]<?php
$my_array = array();
exec(‘powershell.exe -command “Get-XASession | Select -Property accountname, logontime | where {$_.accountname -LIKE “domainJoeB” } ” <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 domainjoeb be escaped from the PHP:
[CODE]exec(‘powershell.exe -command “Get-XASession | Select -Property accountname, logontime | where {$_.accountname -LIKE ‘. “domainJoeB” . ‘} ” <NUL ‘, $my_array);`
I get nothing returned. I ultimately want to do this with a variable captured from an HTML form wherein the user supplies the accountame, but for now am just trying to see if this can work with a hard-coded User ID. I think I’m being PHP syntax challenged.