Add Single Threaded Apartment (STA) Switch to Properties of Invoke PowerShell Activity

Hello UiPath,

today I tried Windows Inter Process Communication (IPC) via Windows clipboard. To set some text in the clipboard I want to use a PowerShell script.

Set-Clipboard "Hello World from PowerShell"

The PowerShell script itself works inside ISE as expected. So I create an easy sequence inside UiPath.

SetClipboard001

It is very easy to understand. I read the PowerShell script as text, invoke it and after that I want to get the text from the clipboard, which was set by the PowerShell script, and print it.

But I got this error message:

SetClipboard002

In my opinion could it be profitable to add an additional Single Threaded Apartment (STA) switch to your Invoke PowerShell activity, and that is my suggestion. I assume (and hope) it is very easy to realize, because the dotNET Framework offers in the namespace System.Management.Automation.Runspaces in the class Runspace the property ApartmentState to do that. I could looks like this.

SetClipboard003

On this way we have the possibility to use PowerShell scripts which includes controls, features or static methods as explained in this blog of SAPIEN.

Thanks for all your efforts and best regards
Stefan

Thanks for sharing some beautiful information guys and I agree with you.