Reputation: 21
I am using following code for running exe from PowerShell. However, it is throwing the error mentioned in the subject.
$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
Error:
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
Upvotes: 0
Views: 2783
Reputation: 825
Why not use -Credential Get-Credential? it seems a bit pointless as well trying to convert an item to a secure string if you are displaying it plain text, this will mean it gives you a prompt for username and password.
But if thats the route you want to go down then this should work.
$MyCredential=New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList $Uid, ($pwd | ConvertTo-SecureString -AsPlainText -Force)
Upvotes: 0