While running powershell using invoke activity it throws exception "windows powershell run as administrator"

Hi @Mahashankaripazhani

Supported by this thread, I was able to make a simple process:

image

However, running this will prompt the UAC (which would need to be disabled for this to work, which is highly not recommanded).

Actually, there is a solution to it :slight_smile: (credit to out of our awesome uipathers). See his explanation below:

I use the activity invoking a script. If the script tries to invoke:
Start-Process notepad.exe -Verb runAs
then the UAC dialog will appear defeating the purpose.

If the script instead says:
$credential = New-Object System.Management.Automation.PsCredential(“admin”, (ConvertTo-SecureString “Passw0rd1” -AsPlainText -Force))
Start-Process notepad.exe -Credential $credential

then all is well and the process is run as an administrator without a UAC dialog coming up.

This method requires a prior relaxation of the ability to execute scripts using “Set-ExecutionPolicy”.

Link to .xaml and ps1 script here:
run_as_admin.zip (1.7 KB)

3 Likes