Douglas Anderson
Douglas Anderson

Reputation: 4690

How to user Powershell 'invoke-expression' to run an executable as a different user

I have a c++ service application that launches a Powershell script (powershell.exe script.ps1). In the script an executable is run but needs to be run with different user credentials. Is there a way to do this in Powershell with the invoke-expression cmdlet or some other way?

Upvotes: 4

Views: 7163

Answers (1)

Keith Hill
Keith Hill

Reputation: 201652

Try Start-Process e.g.:

Start-Process cmd.exe -arg "/k whoami.exe" -Credential (Get-Credential)

Of course, for your script you will need to create a credential programmatically rather then using the Get-Credential which prompts for username/password.

Upvotes: 6

Related Questions