2013-08-30 1 views
3

다른 스크립트를 호출하고 해당 스크립트의 출력을 반환하기 위해 ProcessStartInfo 및 Process를 사용하는 코드가 있습니다.ProcessStartInfo 및 PowerShell의 프로세스 - 인증 오류

불행히도 오류가 발생하고 문제를 해결하는 방법을 잘 모릅니다. 내가 할

#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 

오류는 다음과 같습니다

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 

가 어떻게이 문제를 해결할 수 있습니까?

답변

3

꽤 많이, 당신에되지 밖으로 철자?

"로그온 실패 : 알 수없는 사용자 이름 또는 잘못된 암호"

(첫 번째 오류 라인). DOMAIN 별도의 속성에 제공되어야한다

참고 :

$startInfo.Username = "Username" 
$startInfo.Domain = "DOMAIN" 
+1

나는 동일한 자격 증명이 도메인 및 사용자 이름에 다른 코드에서 제대로 – Glowie

+0

별도의 사용자 이름을 사용했기 때문에 사용자 이름과 암호가 올바른지 확인한에게 (편집 참조) - 문제가 해결 되었습니까? –

+0

내가 사무실로 돌아올 때 이것을 시험해 보겠습니다. 좋은 주말 보내세요! – Glowie