This is the minimum lines of script that would reproduce my issue:
$user = 'usr'
$password = 'Password1'
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
Start-Process -Credential $mycreds -FilePath 'C:tempSetup.exe' -ArgumentList '/features + /q /norestart' -Wait
When running in ISE, it successfully launches the installer. But when running in console, it silently exits, without any error message. I tried launching the console as admin or not, didn’t make a difference.
It also works if I remove -Credential $mycreds
, which will install to the current user, but I want to install it as a different user.
I’ve read posts about similar questions, it seems ‘scope’ is the likely issue. But I don’t understand why, or which variable(s) I have scope issue on. $mycreds
prints out the right credential, and I don’t really have any other variable in that Start-Process
call.
Yefei Gao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
12