Run as different user, plus elevated

The Scenario

I have a user Joey Bloggs, who  has recently been migrated to a new domain DOMAINB.TEST. He’s currently logged on to a client in the DOMAINB.TEST domain. However he needs to run a powershell script against servers still residing in DOMAINA.TEST using his old DOMAINA credentials. NB there is a two-way trust between the domains.  However he also needs to run the script within an elevated Powershell ISE window.

The problem

Windows only provides the option to run as administrator OR a different user. I need to do both.

run_as

The Solution

On the DOMAINB.TEST client Joey Bloggs opens an elevated command prompt and enters:

runas /netonly /user:jbloggs@domaina.test PowerShell_ISE.exe

He’s them prompted to enter his DOMAINA.TEST credentials. The ISE sessions opens elevated and running as jbloggs@domaina.test.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Of course this would work just as well in the same domain. In this scenario Bill is logged in and for some reason needs to run a cmdlet or script as Joey Bloggs and within an elevated session. Bill would complete the following steps:

  1. Open an elevated command prompt
  2. Run runas /netonly /user:jbloggs@domaina.test PowerShell_ISE.exe
  3. Enter Joey’s credentials.

 

Disclaimer: provided “AS IS” with no warranties and confer no rights

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s