IIS 7 and Above
powershell script does not complete when launched from IIS
Last post Jul 29, 2012 11:29 AM by theboywonder
Aug 27, 2009 03:40 PM|jchertudi|LINK
I believe this is the best forum for this, we have a php-cgi script that launches a power shell command, which in turn submits a job to a queuing system.
We are running php on IIS7 x64. I believe that somewhere this is a permissions issue, but have not been able to crack the code yet. Only when I run our application pool with the account of a system administrator will the job submit to the queue. I have tried
to run the application pool with either NetworkService and a domain guest account. Normal php pages execute, but page that launches powershell will time out and a hanging powershell.exe is left running on the web server doing nothing.
if i run a powershell command window on the web server directly as the same domain guest account, then the job will complete. We just can not seem to get php to submit a powershell command that completes.
Any advice or ideas? I have been chasing this as a security issue, I don't want to run this site as a system admin!
Sep 01, 2009 02:35 AM|Leo Tang - MSFT|LINK
Please check the Event Viewer to see if any errors are occurring that cause powershell.exe hanging.
Sep 02, 2009 01:41 AM|sergeia|LINK
Worker process doesn't have an access to the whole configuration system. It is by design. PowerShell snapin will report access problem, that may or may not be reported in the log. As far as I know, we didn't test the snapin when hosted in the worker process.
Sep 23, 2009 03:23 AM|sergeia|LINK
See my reply on another thread, it is applicable here too. Main difference for you will be hosting PowerShell from inside of PHP. I am not familiar how PHO could execute managed code, but you probably could
only start it as separate process, in this case you have to write your script that will take credentials as parameters and execute start-job and then pass this script in command line when you start PowerShell.
Jun 25, 2010 01:14 PM|Chancer|LINK
Jul 29, 2012 11:29 AM|theboywonder|LINK
We use PHP and Powershell at lot at work. I've blogged about our setup to get this working here:
And yes, Chancer is right. Your PHP should be of the format:
shell_exec("powershell -command $ScriptPath -someparam '$value'< NUL");
"powershell -command $ScriptPath -someparam '$value'< NUL"