shell - PHP | Passing parameters into Powershell script -
i trying create php application runs powershell scripts.
i have file called "change.ps1" powershell script, here content of file:
param([string]$username, [string]$password) import-module activedirectory $newpwd = convertto-securestring -string "$password" -asplaintext –force set-adaccountpassword $username -newpassword $newpwd –reset
now have php page uses shell_exec() function run script , pass 2 parameters it, can see above used in ps1 file ( $username, $password):
$psscriptpath = "c:\inetpub\htdocsscripts\change.ps1"; shell_exec("powershell.exe -executionpolicy remotesigned -file" . $psscriptpath . " -username \"" . $username . "\" -password \"" . $password . "\"");
at moment not work (the page never finishes loading aka times out). question is, doing correctly? have gone wrong. theory behind relatively simple, use php pass variables through parameters powershell script.
thanks taking look, , let me know if have questions.
update: tried running script directly via cmd see if problem in script self. here error shown: http://puu.sh/axuh3/b8db154625.png
second update: have fixed error on cmd, encoding issue. when try run php page, still time out issue: http://puu.sh/axedy/22cc87310c.png
ok, seems missing something.
you need point absolute path of script. if saw message on wizpert, did cd command directory of script ensure correct environment:
c:\>cd c:\my\directory\with\powershells
then can execute powershell variables on it. try via cmd see if produces messages. if see there timeout, means process or hanging or web user not have enough rights execute shells.
if so, modify php.ini or whatever let know www-data user (in apache, not sure on iis) has rights execute commands.\
also executing parameter wrongfully:
param([string]$username, [string]$password) import-module activedirectory $newpwd = convertto-securestring -string $password -asplaintext –force set-adaccountpassword $username -newpassword $newpwd –reset
make $password without quotes on powerscript.
Comments
Post a Comment