Having issues with UiPath and Powershell

I am trying to run a Powershell script in UiPath and I am having issues with the get-clipboard command. The command just gets what’s in the clipboard and writes it to a word file. It works fine to run as a standalone. But when I use Run Powershell Script in UiPath it writes a blank line to the text file. If I change the variable to a string then it works.

This is the script

$data = get-clipboard

Add-content -path “blah blah” -value $data

If I change $data to “hello world” then it works.

Any ideas?

Regards

Hi @chinmoypborah,

Funny thing …
I’ve tested the behavior and the function does not return any value at all when invoked through UiPath (you can check it by returning the $data variable with PowerShellVariables in misc section of the Invoke Power Shell activity) … does not look like we can do anything about the way UiPath invokes the method

a possible, and more uipathy, workaround would be to:

  1. get value from clipboard with Get From Clipboard activity
  2. store retrieved value into a variable
  3. pass the variable into Invoke Power Shell Parameters

image

Hope you find the workaround helpful :slight_smile:

Best Regards,
Filip

Please also remember to set Property IsScript in Invoke Power Shell

2 Likes

I was able to Get-ClipBoard text by simply invoking PowerShell in the CommandText:

"
PowerShell @’
Add-content -path .\test.txt -value (Get-Clipboard)
'@
"

Hi @iRon,

Invoking PowerShell from Invoke Powershell activity is not the neatest of the solutions but certainly does the trick too :slight_smile:

Cheers!
Filip

1 Like