I'm creating a powershell script that does some automatic setup of new computer deployments. I'm in a situation where I want to launch an executable as a regular non-admin user from an elevated admin powershell console instance. The reason why is because if I launch from an elevated prompt/script, the executable generates an error. Here's the structure of the command:
Start-Process -FilePath (${Env:CommonProgramFiles(x86)} + "\sample.exe") -ArgumentList "/PRODUCT:sample", "/VERSION:2.0", "/MODE:1"
I did some searching and found the opposite of what I need (non-admin to admin) here https://technet.microsoft.com/en-us/library/hh849848.aspx but I only saw RunAs
to elevate to admin.
Setup:
- Windows 10 Education
- PS 5
Resolution
Since psexec
didn't offer a solution for suppress login, I ended up starting the process as follows:
$username = Read-Host "Please enter in a valid username "
$password = Read-Host "Please enter in a the account password " -AsSecureString
Start-Process -Credential (New-Object System.Management.Automation.PSCredential($username, $password)) -FilePath (${Env:CommonProgramFiles(x86)} + "\sample.exe") -ArgumentList "/PRODUCT:sample", "/VERSION:2.0", "/MODE:1"
It doesn't solve the issue perfectly, but the user can stay in the script at least.