I am trying to create a PHP application which runs powershell scripts.
I have a file called "change.ps1" which is a powershell script, here is the content of that file:
Param([string]$username, [string]$password)
Import-Module ActiveDirectory
$newpwd = ConvertTo-SecureString -String "$password" -AsPlainText –Force
Set-ADAccountPassword $username -NewPassword $newpwd –Reset
Now i have a PHP page which uses the shell_exec() function to run this script and pass TWO parameters to it, which you can see above is used in the ps1 file ( $username, $password):
$psscriptpath = "c:\inetpub\htdocsscripts\change.ps1";
shell_exec("powershell.exe -executionpolicy remotesigned -File" . $psscriptpath . " -username \"" . $username . "\" -password \"" . $password . "\"");
At the moment this does not work (the page never finishes loading aka times out). So the question is, am i doing this correctly? where have i gone wrong. The theory behind this is relatively simple, use PHP to pass variables through as parameters into a powershell script.
Thanks for taking a look, and let me know if you have questions.
UPDATE: I tried running the script directly via the cmd to see if the problem was in the script its self. Here is the error i was shown: http://puu.sh/aXuH3/b8db154625.png
SECOND UPDATE: I have fixed the error on the CMD, it was an encoding issue. However when i try to run the php page, i still get the time out issue: http://puu.sh/aXEdY/22cc87310c.png