ProcessStartInfo et des Processus de PowerShell - Erreur d'Authentification
J'ai un code qui utilise ProcessStartInfo et Processus d'invoquer un autre script, et pour revenir à la sortie de ce script.
Malheureusement, j'obtiens des erreurs, et je suis pas sûr de la façon de les résoudre.
#script1.ps1
$abc = $args
$startInfo = $NULL
$process = $NULL
$standardOut = $NULL
<#Previously created password file in C:\Script\cred.txt, read-host -assecurestring | convertfrom-securestring | out-file C:\Script\cred.txt#>
$password = get-content C:\Script\cred.txt | convertto-securestring
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = "powershell.exe"
$startInfo.Arguments = "C:\script\script2.ps1", $abc
$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
$startInfo.CreateNoWindow = $false
$startInfo.Username = "DOMAIN\Username"
$startInfo.Password = $password
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
$process.Start() | Out-Null
$standardOut = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
# $standardOut should contain the results of "C:\script\script2.ps1"
$standardOut
Les erreurs que je reçois sont:
Exception calling "Start" with "0" argument(s): "Logon failure: unknown user name or bad password"
At C:\script\script1.ps1:46 char:15
+ $process.Start <<<< () | Out-Null
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At C:\script\script1.ps1:47 char:49
+ $standardOut = $process.StandardOutput.ReadToEnd <<<< ()
+ CategoryInfo : InvalidOperation: (ReadToEnd:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "WaitForExit" with "0" argument(s): "No process is associated with this object."
At C:\script\script1.ps1:48 char:21
+ $process.WaitForExit <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Comment puis-je résoudre ce problème?
OriginalL'auteur Glowie | 2013-08-30
Vous devez vous connecter pour publier un commentaire.
C'est assez bien indiqué à vous, n'est-ce pas?:
(première ligne d'erreur).
Noter que le DOMAINE doit être fournie dans la séparation des biens:
Nom d'utilisateur séparé dans le Domaine et le nom d'utilisateur (voir edit) - cela veut-il résoudre le problème?
Je vais essayer à mon retour au bureau. Avoir un grand week-end!
Fait-il travailler pour vous?
Oui, j'ai même marqué votre réponse comme la solution!
OriginalL'auteur Erik A. Brandstadmoen