I am attempting to run an executable through PowerShell 1.0 using another user's credentials. My current script is the following:
$username = "adminuser"
$password = "thepassword"
$secstr = ConvertTo-SecureString -String $password -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secstr
Start-Process powershell.exe -verb runas -Credential $cred -File C:\Users\Public\myexecutable.exe
The error I receive is the following:
Error: Start-Process : This command cannot be run due to the error: The handle is invalid.
At C:\Users\Public\privy2.ps1:8 char:1
+ Start-Process powershell.exe -Credential $cred
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
When using the command without credentials, the script works and the executable runs:
Start-Process powershell.exe -verb runas -File C:\Users\Public\myexecutable.exe
Any ideas as to why I am getting the The handle is invalid error
?
Per .NET Process Start Process Error using credentials (The handle is invalid), I have tried adding redirects but the same error persists.