Copy and rename file with PowerShell

Hi Team

Currently, I am using the File Command Copy list of files and the File Command Rename list of files.


I want to do it in one step. I cannot see a File command that can do that.
I tried PowerShell, but this does not work:

Copy-Item -Path $Source -Destination $Destination

Not sure how to use the $input to refer to the fields in the table


It’s the “Copy/move list of files” command. You will need to produce a list a files first using the “List files” action, then use the column with the list of files in the “Copy/move list of files” command.

Thanks, Dmitry.

I am missing something.
The Copy/Move list of files - only allows you to list the folder destination - not what the new file’s name should be.

This is how I used it:

Source - is complete path i.e. …\network1\Blue.csv
The destination - only a folder i.e. …\network2
I cannot see how I can use the Top folder + new name here

Then I rename it:


You refer to the “list file” action - I have a list of the files.

Not sure how to copy from full path to path + new name as the action only asks for folder destination.

This solution works, but I wanted 1 step in stead of 2

Oh, I missed that part. My bad.

In this case, it should be two operations. One - copy the files to another folder. The other one - rename them in that folder. Both operations can be done with the “File command” action. You will need a lookup table with old file names and new file names (after renaming) for the “Rename a list of files” command to work.

Thanks, Dmitry
I have already done it, but this sometimes gives issues with sinking to SharePoint.

Can you please help me understand how I can use PowerShell to get this done in one step:

Copy-Item -Path $Source -Destination $Destination

Not sure how to use the $input to refer to the fields in the table.

Hi @Rykie

If you have a table with full paths to files you want to copy in a column, you could use such a cmdlet to copy them

$input | Foreach-Object {
 Copy-Item -Path $_ "<replace-with-your-destination-folder>" 

In EasyMorph it should look something like this. Pick Column option for input pipeline and select column containing full file paths:

Thanks, Olysak.

The above works fine if the filename stays the same, but I need to change the filename.

Do you have any documentation that I can read on how I can use Input: Table and refer to fields in the table?

My table will have 2 fields Source and Finaldestination (both complete paths)
How do I Use the table with two values?

I tried a few options but cannot get this to work.

Something like: (Table - referring to field names)

$input | Foreach-Object {
Copy-Item -$Source $ Finaldestination

I also tried Column:
$input | Foreach-Object {
$td= if(-Path -contains “Target”) {“test1.xlsx”} ElseIf(-Path - contains “User_Sal”) {“US.xlsx”} Else {“other.xlsx”}
Copy-Item -Path $_ “{Top Path}$($td)”

Where {Top Path} is a parameter
{Top Path}$($td) - is working - I only need to get the variable setup

Hi @Rykie

I don’t think you can address specific fields in PowerShell input stream. In Table mode $input contains all table items in row-major order, like this:

$input for such table will have values in this order: a11, a12, a13, a21, a22, a23 etc.

I suppose you could separate them in the PowerShell script, minding that for example for two-column table odd-numbered $input items are source file names, even-numbered are destinations but this is extremely brittle way that would break if input columns are reordered or any extra columns are added to the input table.

I would suggest to adhere to @dgudkov 's advice of using File command action for two-step renaming.

Thanks, all for your help