0

I'm making a web page for the association I work for to check the daily data. For each data in the array, there is a background-color that is green if the data exists and red if it's not the case. The data I'm looking for is located on severals servers I can access to thanks to PowerShell with the cmd powershell.exe Invoke-Command -Computer Server -ScriptBlock {Test-Path the_path_to_my_file}, but when I make an exec function in php with this line in first argument and an array in second argument, the array remains empty.

I've tried this on my professional computer and it works but I have to log in to the server to access the data because I'm not administrator, but the web page is located on a server I administrate.

I know I can access the server with the cmd powershell.exe Invoke-Command -Computer Server -ScriptBlock {Test-Path the_path_to_my_file} and the exec command works with an echo for example.

I've also tried with passthru and SHell_Exec and there is no result either

function existe_srv($srv, $file){
      exec("powershell.exe Invoke-Command -Computer ".$srv." -ScriptBlock {Test-Path \"".$file."\"}", $out );
      if ($out[0] == True){return 'RGB(0,255,0)';}
      else {return 'RGB(255,0,0)';}
    }

background-color:
Notice: Undefined offset: 0 in D:\XAMP\htdocs\Test_opti_cartes\supervision_donnees_quotidiennes.php on line 37

techguy1029
  • 743
  • 10
  • 29
  • Maybe add `2>&1` to the end of the first `exec` arg to see if any errors occur – Mathias R. Jessen Aug 12 '19 at 14:09
  • I think my php command can't even launch powershell while the cmd still works... – Axel Vannoorenberghe Aug 12 '19 at 14:46
  • Even if I add the path to powershell.exe it can't return any bollean – Axel Vannoorenberghe Aug 12 '19 at 14:54
  • Sounds like a [double hop authentication problem](https://stackoverflow.com/questions/14928350/how-can-i-fix-the-kerberos-double-hop-issue). i.e. running it while locally logged in works because you run it all under your account, but "who" runs it on the web server? – HAL9256 Aug 12 '19 at 20:01
  • Or, the issue could be that powershell.exe returns a single int value, and you are trying to access it like an array. In your scriptblock can you simply do something like `return 2` and display the output? you may have to do: `shell_exec` from [this answer](https://stackoverflow.com/a/5319219/2150063) in order to get the *output* instead of the return value. – HAL9256 Aug 12 '19 at 20:15
  • I've tried with shell_exec and it still doesn't work, I think the web page can't access the servers in question because even if I had the option -Credential there is no window opening to enter my password... – Axel Vannoorenberghe Aug 13 '19 at 08:46

0 Answers0