Estoy tratando de ejecutar un script de powershell desde PHP, pero parece que no funciona.ejecutando un script de Powershell desde php
El script 'newEvent.ps1' crea un evento en el servidor de Exchange.
$psPath = "powershell.exe";
$psDIR = "C:\\wamp\\www\\ant\\assets\\ps\\";
$psScript = "newEvent.ps1";
$runScript = $psDIR. $psScript;
$runCMD = $psPath." ".$runScript." 2>&1";
echo "\$psPath $psPath <br>";
echo "\$psDIR $psDIR <br>";
echo "\$psScript $psScript <br>";
echo "\$runScript $runScript <br>";
echo "\$runCMD $runCMD <br>";
exec($runCMD,$out,$ret);
echo "<pre>";
print_r($out);
print_r($ret);
echo "</pre>";
Genera:
$psPath powershell.exe
$psDIR C:\wamp\www\ant\assets\ps\
$psScript newEvent.ps1
$runScript C:\wamp\www\ant\assets\ps\newEvent.ps1
$runCMD powershell.exe C:\wamp\www\ant\assets\ps\newEvent.ps1 2>&1
Array
(
[0] => File C:\wamp\www\ant\assets\ps\newEvent.ps1 cannot be loaded because the execut
[1] => ion of scripts is disabled on this system. Please see "get-help about_signing"
[2] => for more details.
[3] => At line:1 char:39
[4] => + C:\wamp\www\ant\assets\ps\newEvent.ps1 <<<<
[5] => + CategoryInfo : NotSpecified: (:) [], PSSecurityException
[6] => + FullyQualifiedErrorId : RuntimeException
[7] =>
)
Si me quedo powershell.exe C:\wamp\www\ant\assets\ps\newEvent.ps1
en la línea de comandos, funciona bien.
Esta es la primera vez que intento algo como esto. Ejecuté Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
pero todavía me da el mismo error. De hecho, ejecuté Set-ExecutionPolicy unristricted
, pero sigue siendo el mismo.
mira la línea de comandos que estás ejecutando. –
Asegúrese de entrar en las instancias de 32 bits y de 64 bits y configure la política de ejecución, luego vuelva a intentarlo.-> Set-ExecutionPolicy Sin restricciones –