我是个Citrix管理员,一个熟练的PowerShell用户,一个使用PHP的初学者。不过,我已经创建了几个运行简单PowerShell命令的PHP页面,如本例所示:
PHP片段示例,演示如何成功地运行高级命令:
<?php
$my_array = array();
exec('powershell.exe -command "Get-XAAdministrator|Select -Property AdministratorName,AdministratorType" <NUL ', $my_array);
?>但是,当我试图利用前面的HTML页面中要求用户ID的POSTED变量时,我可以在PHP页面中很好地提取该变量。我可以回显并将其显示为JoeB,例如在生成的PHP页面上。但是它需要输入到PHP/PowerShell语法中,用双引号括起来。
因此,这个片段不起作用:
<?php
$my_array = array();
exec('powershell.exe -command "Get-XASession | Select -Property servername, accountname, logontime | where {$_.accountname -LIKE $ID}" <NUL ', $my_array);`--这是它在普通powershell控制台中的外观和工作方式:
Get-XASession | select -Property servername, accountname, logontime | where { $_.accountname -LIKE "JoeB" } (请注意,用户ID JoeB是双引号。)
返回到PHP尝试这样做:-变量$ID是输入到前面的$ID表单中的用户ID。
如有任何指导,将不胜感激。
发布于 2015-07-16 20:15:31
您需要的内容如下:
<?php
$my_array = array();
exec('powershell.exe -command "Get-XASession | Select -Property servername, accountname, logontime | where {$_.accountname -LIKE '.$ID.'}" <NUL ', $my_array);您遇到的问题是,您不能像在这里那样替换单引号中的变量。它只适用于双引号。我所做的,是用引号'结束字符串,并使用点. (意思是“串联”),然后使用$Id (作为来自POST的字符串),然后再连接字符串的其余部分。
祝好运!
https://stackoverflow.com/questions/31463406
复制相似问题