Trouble launching powershell

I want to close leftover chrome windows which open with I have my UiPath workflow click Download.

I have a Powershell script called closechromeps.ps1 which contains one line:

stop-process -name “chrome” -force

I’m using an Invoke Powershell activity with the command text: “C:\UNFIRobot\UNFIRobot\closechromeps.ps1” and the ISScript checked.

When I run the UiPath process it fails saying

19.6.0+Branch.master.Sha.adf20656f41da84cdec5e5620b62276717eb7319

Source: Invoke Power Shell (Throw)

Message: File C:\UNFIRobot\UNFIRobot\closechromeps.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

Exception Type: System.Management.Automation.PSSecurityException

RemoteException wrapping System.Management.Automation.PSSecurityException: File C:\UNFIRobot\UNFIRobot\closechromeps.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. —> RemoteException wrapping System.UnauthorizedAccessException: File C:\UNFIRobot\UNFIRobot\closechromeps.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

--- End of inner exception stack trace ---

at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

But I have set the execution policy to unrestricted

PS C:\Windows\system32> get-executionpolicy -list

    Scope ExecutionPolicy
    ----- ---------------

MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted

I can drop C:\UNFIRobot\UNFIRobot\closechromeps.ps1 into a powershell command window, hit enter, and it runs and closes chrome.

What am I doing wrong?

Any advice greatly appreciated! Thank you in advance.

Ravi

Hello @ravin,
Since you only trying to execute a single command to close a browser pass the Stop-Process as a string into “CommandText” and Name “chrome” as a string into “Parameters”.

You can also use “Kill Process” activity and pass “chrome” as the process name. This will perform the same action.

@ravin - The exception tells you exactly the issue. Even a link to explain further. You can’t execute PS on your computer because of system management policies.

If your project doesn’t require PowerShell to run, then @karavinds solution should work. Otherwise, you may need to speak with the SysAdmin.

Thank you Karavinds!

Kill Process is exactly what I need and works fine.

But I’m also wanting to learn how UiPath works with Powershell. Your first suggestion is what we tried first. Using that method I’m now stuck with an error complaining about not passing a required parameter “ID” If that is the process ID I would not know that at run time. Powershell itself will run the command without an ID parameter.

In any case, thank you. I am a newbie and didn’t know the Kill Process command.

Cheers,

ravi

Since

Thanks for the suggestion to contact the sysadmin, Sagacity. Unfortunately, LOL, I am the IT Manager and my SysAdmn was sitting beside me as we tried everything. We have full rights to our servers.

I did follow the link and read the Microsoft doc and we did use set-excecutionpolicy to give the computer the right to run powershell. And we were able to run the command in powershell. My message showed the output of get-executionpolicy which shows that the localcomputer scope execution policy is unrestricted. We thought that should do it.

Are we missing something?

Cheers,

Ravi

Ravi, @ravin
You should save your script file as txt, use Read Text File activity to read the file content and pass it as CommandText into Invoke Power Shell. You also need check IsScript checkbox under Misc.

InvokePS.zip (1.4 KB)

2 Likes

Hi Karavinds,

That’s great! Thanks so much for the sample code. I tried it out and it works too. I much appreciate your time in helping me.

Best regards,

Ravi

I don’t know. That seems quite odd. It may be that the UI Path Robot is executing under different privileges. Although, may be a moot point now as it seems like you’ve got it working.

Cheers

The policy scope of ‘LocalMachine’ is separated 32bit and 64bit.
UiPath uses 32bit scope.
I guess you have confirmed 64bit setting.
Please run get-executionpolicy -list commend in ‘PowerShell (x86)’ again.
(not run in ‘PowerShell’. It is 64bit version)

Regards