How to pass a parameter in Powershell script in UiPath?

Hi All

We need to copy a file from a remote server to our local machine using Power Shell script. We are using Power shell script inside a for loop and want to pass the source file as a parameter,

How can we pass a variable inside the script so that it will take the source file string from the for loop ?

Hi @kkpatel ,

Have you Checked the Below Post :

could be interpretated as the powershell script file should be passed dynamicly. If this is meant:

  • read text file - reading the file with the PS Script - strPSscript
  • pass strPSScript
    grafik
  • ensure that isScript is activated

use variables / parameters as described above / other posts

Hey @supermanPunch… Thank you so much for sharing this.

But somehow I am not able to open that Main.xaml. Could please help me with the screenshot, how the variables are used ? It would be a great help for me.

@kkpatel ,

Check the Screenshot below :

Thank you so much Arpan. I was also able to open that file.

I will try to implement this and check.

1 Like

Hi @supermanPunch @ppr

This is my script:
“Copy-Item -Path $SourceFile -Destination $DestnPath -PassThru”

where I am trying to copy a file from source to destination.

$SourceFile and $DestnPath are my two variables. But it is throwing me error.

Invoke Power Shell: Cannot bind argument to parameter ‘Path’ because it is null.

ensure the SourceFile variable is correctly populated with a value
May we ask you to share the Powershellvariables settings with us?

image

@kkpatel ,

Could you Remove the $ in the Name and Check again ?

Yes it was wrong. $ is not required in the parameter name.

I removed but still the same error.

I doubt, is my script right ?

“Copy-Item -Path $SourceFile -Destination $DestnPath -PassThru”

image

@kkpatel ,

Looks like there is some kind of a Bug in Invoke Powershell Activity.

Comment the Invoke Powershell you have created. Drag another Invoke Powershell Activity. Use the Command Below :

Copy-Item -Path $SourceFile -Destination $DestnPath

I don’t think there is a Need of -PassThru

Keep the IsScript enabled.

Make sure that you Configure the Powershell Variables in One Shot.

The reason Is I think the Powershell Activity is again referring to the Old Values which once had provided the error. It seemed to be the case at my End.

However, if at first, we do Proper Configurations, then we shouldn’t receive such errors.

2 Likes

Wow !!!

Thanks @supermanPunch

It worked !!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.