Invoke PowerShell as a Different User

Hey gang,

Does anyone know of a way to Invoke PowerShell as a user other than the user the robot is running as (similar to Run as Different User)?

I need to do some AD and Exchange work with variables created in UiPath. The process works fine if I run in Studio while logged in with an AD admin account but we don’t (and won’t) have a robot running under those credentials.

The only way I can come up with is use Invoke Code to start PowerShell with different credentials (from Orchestrator) and passing it a PS script along with the UiPath variables as arguments. Should work but seems messier than it needs to be.

Thanks.
Troy

I am trying to do the same thing and am stuck as well. I hope someone else has this figured out. Stumped

Hi @tmays

Hopefully this post will help you:

Hey @loginerror,

I guess it would be helpful if I followed up with how I handled. It’s ugly but didn’t find a better way. This was for creating a new AD user, adding to groups, creating a new session to Exchange, and adding a user.

I read that post and the difference was I needed to run PS as a different user, not elevate the current user to admin.

I used Invoke Code Invoke Code to start PS with the different account and then called the PS script with the variables located in the argument collection.

Dim ps As New Process

ps.StartInfo.UseShellExecute = False
ps.StartInfo.FileName = “powershell.exe”
ps.StartInfo.WorkingDirectory = “C:\Windows\System32\WindowsPowerShell\v1.0”

'Username and Password from Orchestrator Cred
ps.StartInfo.UserName = adexch_uname
ps.StartInfo.Password = adexch_pwd
ps.StartInfo.Domain = “domain.com

‘Pass arguments to create new users and create new session to Exchange for mailbox
ps.StartInfo.Arguments = “-file c:\UiPath_Scripts\CreateUser_AddMailbox.ps1” & " " & FirstName & " " & LastName & " " & _
NewUsername & " " & UPN & " " & GenPassword & " " & “”“” & NewUserOU & “”“” & " " & BusPhone & " " & “”“” & _
ADUserDescription & “”“”’ & " " & adexch_uname & " " & adexch_pwd & " " & url_ps_exchange

ps.Start()

The PS file it calls .CreateUser_AddMailbox.zip (717 Bytes)

HTH somebody. :slightly_smiling_face:

Troy

2 Likes