Cannot seem to pass a variable to PowerShell command in a PHP script


i can run simple xenapp powershell commands in php script. example works many other commands:

<?php     $my_array = array();     exec('powershell.exe -command "get-xaadministrator|select -property administratorname,administratortype" <nul ', $my_array);  ?>

i hit wall though trying posh command part of php script accept variable posted html form. not work (and know variable extracted):

<?php     $my_array = array();    exec('powershell.exe -command "get-xasession | select -property servername, accountname, logontime | {$_.accountname -like $id}" <nul ', $my_array);`

i xenapp sessions result seems variable gets ignored. aha, realized if hard code account name still not work. here's pertinent line:

 exec('powershell.exe -command "get-xasession | {$_.accountname -like "dhe\joeb"} <nul ', $my_array); 

in powershell console of course typed that:

get-xasession | {$_.accountname -like "dhe\joeb"}

so not variable-ingesting issue i've thought these past days. seems have come across php issue wherein inclusion of double quotes define value of accoutname messing php. in php forum advised when trying use variable :

try {$_.accountname -like '.$id.'}"
didn't help. sorry confusing powershell issue php one.

watch this:

$s='powershell.exe -command "get-xasession | select -property servername, accountname, logontime | {$_.accountname -like $id}"' ;

exec($s, $my_array);

print string before handing exec.


\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL