Question impossible lancer script powershell via php

Plus d'informations
il y a 10 ans 11 mois #19334 par Laurent Dardenne
Kevios écrit:

Je n'ai jamais vraiment utilisé la gestion des erreurs

D'avoir un compte rendu avec Resolve-Error ce serait bien...

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 11 mois #19341 par Kevin
Alors, j'ai réussi à récupérer ceci avec resolve-error

PSMessageDetails : Exception : System.InvalidOperationException: Impossible d'ex�cuter cette commande en raison de l'erreur�: Descripteur non valide. � System.Management.Automation.MshCommandRuntime.Thr owTerminatingError(ErrorRecord errorRecord) TargetObject : CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperation Exception FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands .StartProcessCommand ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo PipelineIterationInfo : {0, 0} MyCommand : Start-Process BoundParameters : {[Credential, System.Management.Automation.PSCredential], [A rgumentList, System.String[]], [FilePath, powershell.exe]} UnboundArguments : {} ScriptLineNumber : 19 OffsetInLine : 14 HistoryId : -1 ScriptName : \\SERVEUR\script\Lancement_Powershell_Info_PC.ps1 Line : Start-Process powershell.exe -Credential $cred -ArgumentList \"Start-Process '\\SERVEUR\script\INFO_PC.exe' -Verb runAs \" PositionMessage : Au niveau de \\SERVEUR\script\Lancement_Powershell_Info_PC .ps1�: 19 Caract�re�: 14 + Start-Process <<<< powershell.exe -Credential $cred -Argu mentList \"Start-Process '\\SERVEUR\script\INFO_PC.exe' -Ve rb runAs\" InvocationName : Start-Process PipelineLength : 1 PipelinePosition : 1 ExpectingInput : False CommandOrigin : Internal 0000000000000000000000000000000000000000000000000000000000000000000000000000000 0 Message : Impossible d'ex�cuter cette commande en raison de l'erreur�: D escripteur non valide. Data : {} InnerException : TargetSite : Void ThrowTerminatingError(System.Management.Automation.ErrorR ecord) StackTrace : � System.Management.Automation.MshCommandRuntime.ThrowTermi natingError(ErrorRecord errorRecord) HelpLink : Source : System.Management.Automation

C'est bien ce type de résultat qu'on doit récupérer avec Resolve-Error?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 11 mois #19343 par Laurent Dardenne
Kevios écrit:

C'est bien ce type de résultat qu'on doit récupérer avec Resolve-Error?

Oui, par défaut il affiche la dernière erreur.
Mais c'est illisible.

Quels droits le script PS, exécuté par PHP, a-t-il ? Admin/user ?

As-tu essayé avec un script simple qui t'afficherais si le contexte est admin ou pas. Voir le début de ce script .
Il faut s'assurer si c'est un pb de droits ou de construction de ligne d'appel de start-process.
Là c'est du pifomètre :lol:

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 11 mois #19344 par Kevin
le script powershell a les droits user quand lancé depuis le PHP. Une fois dans le script, l'application se lance avec les droits d'administrateur.

A ce moment-là je peux essayer de faire une élévation de privilège directement dans php.

Voici mon élévation de privilège dans mon script powershell:

[code:1]$username = $Variables.DOMAINE + \"\\" + $variables.USER2
$password = (ConvertTo-SecureString -String $variables.PWD2 -asplaintext -force)
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password[/code:1]

Pour resolve-error, il me sort tout sur mon site PHP. Je vais essayer d'organiser mieux le résultat pour le retransmettre proprement ^^

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 11 mois #19345 par Laurent Dardenne
Kevios écrit:

Pour resolve-error, il me sort tout sur mon site PHP. Je vais essayer d'organiser mieux le résultat pour le retransmettre proprement ^^

je comprends, dans ce tutoriel je propose un gestionnaire d'erreur global, tu peux l'implémenter si tu le souhaites.
Ainsi tu sauvegarderas la collection d'erreur, ce qui facilite le debug/support.

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 11 mois #19346 par Kevin
J'ai réussi à remettre au propre comme je le pouvais le message d'erreur:

PSMessageDetails :

Exception : System.InvalidOperationException: Impossible d'executer cette commande en raison de l'erreur : Descripteur non valide.
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

TargetObject :

CategoryInfo :

InvalidOperation: ( : ) [Start-Process], InvalidOperation Exception

FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

ErrorDetails :

InvocationInfo : System.Management.Automation.InvocationInfo

PipelineIterationInfo : {0, 0}

MyCommand : Start-Process

BoundParameters : {[Credential, System.Management.Automation.PSCredential], [NoNewWindow, True], [ArgumentList, System.String[]], [FilePath, powershell.exe]}

UnboundArguments : {}

ScriptLineNumber : 20

OffsetInLine : 14

HistoryId : -1

ScriptName : \\SERVEUR\script\Lancement_Powershell_Info_PC.ps1

Line : Start-Process powershell.exe -Credential $cred -NoNewWindow: $true -ArgumentList \"Start-Process '\\SERVEUR\script\INFO_ PC.exe' -Verb runAs\"

PositionMessage : Au niveau de \\SERVEUR\script\Lancement_Powershell_Info_PC .ps1 l:20 Caractere:14 + Start-Process <<<< powershell.exe -Credential $cred -NoNe wWindow:$true -ArgumentList \"Start-Process '\\SERVEUR\script\INFO_PC.exe' -Verb runAs\"

InvocationName : Start-Process

PipelineLength : 1

PipelinePosition : 1

ExpectingInput : False

CommandOrigin : Internal


0000000000000000000000000000000000000000000000000000000000000000000000000000000 0

Message : Impossible d'executer cette commande en raison de l'erreur : Descripteur non valide.

Data : {}

InnerException :

TargetSite : Void
ThrowTerminatingError(System.Management.Automation.ErrorRecord)

StackTrace : System.Management.Automation.MshCommandRuntime.ThrowTermi natingError(ErrorRecord errorRecord)

HelpLink :

Source : System.Management.Automation



Est-ce plus lisible? ^^\"

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.113 secondes
Propulsé par Kunena