I'm a Citrix admin, a journeyman PowerShell user, a beginner using PHP. I have though managed to create several PHP pages that run simple PowerShell commands as in this example:
PHP snippet example showing how I successfully run POSH commands:
<?php
$my_array = array();
exec('powershell.exe -command "Get-XAAdministrator|Select -Property AdministratorName,AdministratorType" <NUL ', $my_array);
?>
However when I try to utilize a POSTED variable from a preceding HTML page that asked for a USER ID I can extract that variable just fine in the PHP page. I can echo and display it as JoeB for example on the resultant PHP page. But it needs to be entered into the PHP/PowerShell syntax encased in double quotes.
Thus this PHP snippet does not work:
<?php
$my_array = array();
exec('powershell.exe -command "Get-XASession | Select -Property servername, accountname, logontime | where {$_.accountname -LIKE $ID}" <NUL ', $my_array);`
This is how it would look and work in a normal powershell console:
Get-XASession | select -Property servername, accountname, logontime | where { $_.accountname -LIKE "JoeB" }
(Note that the USER ID JoeB is in double quotes.)
Back to the PHP attempt to do this: - The variable $ID is the USER ID entered into the prior HTML form.
It is being extracted from the HTML form as simply JoeB.
And if it is entered into the HTML form as "JoeB" and extacted likewise it still does not work.
The PHP/PowerShell command actually works, but it displays all XenApp Sessions as it is failing to properly read the value of $ID (accountname) and thus filter the results.
Any guidance is appreciated.