Need to run PowerShell as Admin

Is there any activity in UiPath that would run the PowerShell as admin?

1 Like

Hi

There was thread with discussion on same note
Would recommend to have a view on it

Cheers @john.mari

@john.mari

To run PowerShell as an administrator in UiPath, you can use the “Start Process” activity and pass the required arguments to it. Here’s how you can do it:

  1. Add the “Start Process” activity to your UiPath workflow.

  2. In the “FileName” property of the activity, enter “powershell.exe” to start the PowerShell application.

  3. In the “Arguments” property, enter the following command to run PowerShell as an administrator:

-Command "& {Start-Process PowerShell -Verb RunAs}"

This command starts a new PowerShell process with elevated privileges.

  1. Optionally, you can set the “WorkingDirectory” property to the directory where you want the PowerShell process to start.

Here’s an example workflow to help you understand better:

In this example, the workflow starts PowerShell as an administrator and runs the “Get-Process” cmdlet to retrieve information about the currently running processes. The output is then displayed in a message box.

Note that when you run PowerShell as an administrator, you may be prompted to provide administrator credentials

Hi @john.mari

Try with the below steps

  1. Drag the “Invoke PowerShell” activity onto the workflow.
  2. In the “CommandText” property of the activity, enter the PowerShell command you want to run. For example, you could enter a command to list the contents of a directory:

Get-ChildItem C:\Users -Recurse

  1. In the “Parameters” property of the activity, enter the “-Verb RunAs” parameter to run PowerShell as an administrator:

-Verb RunAs

  1. Save and run the workflow.

Regards
Gokul

I have searched for this solution and read some posts on the forum, which gives me inspirations. And I learn how to use the powershell function “Start-Process” where its parameter “-ArgumentList” can transfer the script we want them run in powershell. It works pretty fine.


@Manju_Reddy_Kanughula can you please share the sample xaml file.

Thanks

Don’t lose your time with this “half-backed” “workarounds” as I did. If you need to keep any sort of session or context amongs subsequent PowerShell calls, each one in its own activiy, this won’t ever work, as the context will end when the first activity finishes.