gpt4 book ai didi

powershell - PowerShell 中的 ProcessStartInfo 和 Process - 身份验证错误

转载 作者:行者123 更新时间:2023-12-01 01:06:19 25 4
gpt4 key购买 nike

我有使用 ProcessStartInfo 和 Process 来调用另一个脚本并返回该脚本输出的代码。

不幸的是,我遇到了错误,我不确定如何解决它们。

#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

我该如何解决这个问题?

最佳答案

对你来说已经很清楚了,不是吗?:

"Logon failure: unknown user name or bad password"



(第一个错误行)。

请注意,DOMAIN 应在单独的属性中提供:
$startInfo.Username = "Username"
$startInfo.Domain = "DOMAIN"

关于powershell - PowerShell 中的 ProcessStartInfo 和 Process - 身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18540505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com