Running Powershell Script from PHP
Hi, 
I am trying to run a Powershell script from PHP using Apache on Windows Server 2008. I am using the following code to launch the powershell script: 
shell_exec('powershell.exe -command C:\PSscripts\helloworld.ps1')

Unfortunately I cannot get the script to run at all. I keep getting the error message in the apache log file:
File C:\PSscripts\helloworld.ps1 cannot be loaded because the execution of scripts is disabled on this system. 

I have used the "Set-ExecutionPolicy" command to set the policy to Unrestricted and the Apache service is running as Administrator but I can't for the life of me get it to run the Powershell script. 
Running the script directly from Powershell works fine.
Any help would be fantastic!  Thanks.
January 10th, 2010 3:09am

Make sure to go into both the 32-bit and 64-bit instances and set the execution policy then retry.  Perl is likely using the 32-bit instance of PowerShell.
Free Windows Admin Tool Kit Click here and download it now
January 10th, 2010 4:21am

Make sure to go into both the 32-bit and 64-bit instances and set the execution policy then retry.  Perl is likely using the 32-bit instance of PowerShell.
Worked like a charm! Turns out that PHP was running the 64bit version but it did not have the correct execution policy. 
Big Thanks! 
January 10th, 2010 5:29pm

works fine for me also, seems like executing Powershell on the command line or from PHP executes two different Powershell, each with it's own set of permissions :-(
Free Windows Admin Tool Kit Click here and download it now
December 11th, 2012 2:32pm

Hello,

I have the exact same issue on w2k8 R2 with IIS 7.5.

I tried these codes from php to execute my command:

$cmd = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command ". e:\myscript.ps1 1;"';
	//$cmd = 'dir';
	if ( $a=exec($cmd) ) {
		echo "ok";
	}

I tried with shell_execute, but it doesn't work. Each time the script goes uuntil having an execute timeout 500 internal error.

How do you go into 64 bit powershell instance to set the policy ?

July 30th, 2013 5:30am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics