启动过程:由于错误,无法运行此命令:登录失败:未知用户名或密码错误

时间:2016-03-15 10:30:26

标签: powershell

我使用以下代码从PowerShell运行exe。但是,它正在抛出主题中提到的错误。

$uid = "ABCDomina\builder"
$pwd = "password"
$Args = "-Verb RunAs -Wait -passthru"
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($uid,(ConvertTo-SecureString -String $pwd -AsPlainText -Force))
Start-Process -FilePath C:\windows\system32\system32\notepad.exe -Credential ($cred) -Argumentlist $Args

错误:

Start-Process : This command cannot be run due to the error: Logon failure:
unknown user name or bad password. 
At C:\CD_Clinical\Nightly\DataLabs\Untitled1.ps1:5 char:1
+ Start-Process -FilePath C:\windows\system32\system32\notepad.exe -Credential ($c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
     + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

1 个答案:

答案 0 :(得分:0)

为什么不使用-Credential Get-Credential?如果您将项目显示为纯文本,尝试将项目转换为安全字符串似乎有点无意义,这意味着它会提示您输入用户名和密码。

但是,如果这是你想要的路线,那么这应该有效。

$MyCredential=New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList $Uid, ($pwd | ConvertTo-SecureString -AsPlainText -Force)