PowerShell在Azure上返回空响应

当我尝试在AWS上从PHP运行PS脚本时,它工作正常并返回正确的响应,但是当我尝试 要在Azure上从PHP运行该脚本,它将返回一个空响应。 在两个服务器上使用相同的代码库和相同的Powershell版本,
我使用shell exec()函数在PHP版本7.0.30和Powershell版本V1.0上运行powershell脚本
在IIS中使用Managedpipeline模式是集成的并且流程模型标识是 ApplicationPoolIdentity。 </ p>

以下是运行power shell脚本的PHP代码。</ p>

  $ cmd ='C:\ Windows \ System32 \ WindowsPowerShell \ v1  .0 \ powershell.exe -ExecutionPolicy Bypass -File'。$ scriptPath。'  “'。PARAM1。'”“KEY_FILE_PATH”“'。SCRIPT NAME。'”“''。usERNAME。''''。'  “'.PASSWORD。'”'; 

$ output = shell_exec($ cmd);
</ code> </ pre>

这是我想要的Powershell脚本代码 从上面的命令执行。</ p>

  param($ server,$ keypath,$ scriptname,$ username,$ password,$ distro,$ vncport)
Import-Module -Name C: \ Posh-SSH
$ pass =“temp123”
$ passenc = $ pass | ConvertTo-SecureString -AsPlainText -Force
$ credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist“ubuntu”,$ passenc

$ ssh = New-SSHSession -ComputerName $ server -KeyFile $ keypath -AcceptKey -Credential $ credentials

$ ret = $(Invoke-SSHCommand -SSHSession $ ssh -Command“/ home / ubuntu / $ scriptname $ username $ password $ distro $ vncport”-Timeout 300).Output
\ n $ ret
Remove-SSHSession -SSHSession $ ssh | Out-Null
</ code> </ pre>
</ div>

展开原文

原文

When I try to run PS script from PHP on AWS it is working fine and returning correct response, But When I try to run that script from PHP on Azure it returns an empty response. Same codebase and same Powershell version is used on both servers, I am using shell exec() function to run powershell script on PHP Version 7.0.30 and Powershell version V1.0 Using Managedpipeline Mode in IIS is Integrated and Process Model Identity is ApplicationPoolIdentity.

Here is PHP code to run the power shell script.

$cmd = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File '.$scriptPath.'  "'.PARAM1.'" "KEY_FILE_PATH" "'.SCRIPT NAME.'" "'.USERNAME.'"'.' "'.PASSWORD.'"';

$output = shell_exec($cmd);

Here is the Powershell script code which I am trying to execute from above command.

param($server,$keypath,$scriptname,$username,$password,$distro,$vncport)
Import-Module -Name C:\Posh-SSH
$pass="temp123" 
$passenc = $pass | ConvertTo-SecureString -AsPlainText -Force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "ubuntu",$passenc

$ssh = New-SSHSession -ComputerName $server -KeyFile $keypath -AcceptKey -Credential $credentials

$ret = $(Invoke-SSHCommand -SSHSession $ssh -Command "/home/ubuntu/$scriptname $username $password $distro $vncport" -Timeout 300).Output

$ret
Remove-SSHSession -SSHSession $ssh | Out-Null

doujiao1949
doujiao1949 是否有任何错误?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问