Bonjour tout le monde,
J’ai un script PHP qui exécute un script Powershell. J’utilise PHP version 5.2.x et cela tourne sur IIS 7, Windows Server 2008 R2. La package PHP est installé par la plateforme web.
Tout fonctionnait très bien jusqu'à ce que je migré mon server vers PHP 5.3.10. Le script PHP est simple : il appelle powershell, créé de nouveaux credentials (car IIS tourne avec un utilisateur non administrateur) puis lance un fichier ps1 en utilisant les credentials définis. Voici le script :
Le fichier script (launch.ps1) contient un script, complexe ou non (dans ce test, il exécute simplement get-process). Tout fonctionnait bien avec PHP 5.2.x (bien entendu, en configurant winrm et l’execution policy pour autoriser la commande), mais l’erreur suivante apparaît avec PHP 5.3.10
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <?php $command = 'powershell -ExecutionPolicy Unrestricted -command "$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @(\'administrator\',(ConvertTo-SecureString -String \'MyPassword\' -AsPlainText -Force));Invoke-Command -credential $cred -computername 127.0.0.1 -scriptblock {& c:\temp\launch.ps1}" <NUL'; print($command); print("<br/><hr><br/>"); exec($command, $out); print_r($out); ?>
Est-ce que quelque peut tester (et confirmer) mon problème et peut-être trouver une solution ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Invoke-Command : An internal error occurred. At line:1 char:172 + $cred = New-Object System.Management.Automation.PSCredential -ArgumentList @('administrator',(ConvertTo-SecureString -String 'MyPassword' -AsPlainText -Force)) ;Invoke-Command <<<< -credential $cred -computername 127.0.0.1 -scriptblock {& c:\temp\launch.ps1} + CategoryInfo : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.InvokeCommandCommand
Merci beaucoup pour votre aide et belle journée.
Partager