Invoke power shell issues that work correctly when running from power shell

I am trying to set up a invoke power shell but getting errors. when I run directly from power shell it works properly but when running from Studio i get formatting errors stating that character is invalid. I do not understand what is wrong as I am using the same code to post directly into power-shell and it works without fail;…

@covcreo,

You need to pass the command in command property , but you are passing in continue on error property…

I see what you are saying but get the error when in the command property

On the right side, you need to pass all those string in the commands box , not in the continue on error box…

And don’t give everything in the new line, make all the commands in a single line and append double quotes in the starting and ending

    "$result = "\\server1\D_box_1$\timestamp_processed\pre-process-files-list\combined.csv"$csvs = get-childItem "\\server1\D_box_1$\timestamp_processed\pre-process-files-list\*.csv" #read and write CSV header[System.IO.File]::WriteAllLines($result,[System.IO.File]::ReadAllLines($csvs[0])[0])#read and append file contents minus header foreach ($csv in $csvs)  {$lines = [System.IO.File]::ReadAllLines($csv)[System.IO.File]::AppendAllText($result, ($lines[1..$lines.Length] | Out-String))}"

I get expression expected now…

Is it working?

Or change all the double quotes to single quotes except the first and last @covcreo

single quotes cleared the errors in the command but now i get the error

19.4.2+Branch.master.Sha.e17a3bedca2a7da0d0b716b5f8f765d1d5ef1ddc

Source: Invoke Power Shell (Throw)

Message: The module ‘’$result = ‘’ could not be loaded. For more information, run 'Import-Module '$result = ‘’.

Exception Type: System.Management.Automation.CommandNotFoundException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.Management.Automation.CommandNotFoundException: The module ‘’$result = ‘’ could not be loaded. For more information, run 'Import-Module '$result = ‘’.
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)

do I need to set this as a variable?

Try that as well @covcreo,

Pass the entire command as variable and try.

one more thing , I hope you need to import any packages it seems

Hello @covcreo,
Save the PS script in a text file. Use Read Text file activity to read the file and store it in a variable which can then be passed into Invoke PS activity.

Ive saved the ps as text but in invoke PS i get an error under output

image

Check if your variable is of type Collection<PSObject>, which I believe is the default. The easiest way to create this variable is to use Ctrl+K shortcut while the cursor is in Output property field. This will allow you create a variable in place and would choose the correct variable type automatically. The PSScript should return the value in Collection type to be consumed by UiPath after the PS script completes the execution.

If your script is returning some other type of output like string, configure the TypeArgument accordingly in Invoke Power Shell activity.