Move files from various folders to one

Hi. I’m new to this. I have a list of file names in an Excel spreadsheet. They are in various folders in a drive. I’m looking to go through the list, find the files and move them to a single folder. In other words, go one by one through the Excel file, search for the file and then move it. They all will be moved to the same folder. I appreciate any help you can provide. Thank you.

Ken,
Welcome to the forum. :wave:t3:

That’s a nice task for practicing I think. Do you have any question?

What help do you expect?

This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

Thanks for your help. Do you have any suggestions on where I can go with help to learn and get started? Thanks.

It depends pretty much on how new you are to this …

This video series is somewhat old but I think it’s still worth to watch for beginners

Don’t worry that it is about PowerShell version 3. The basics are still the same.

1 Like

Definitely follow Olaf’s recommendation and take a look at some videos. I’ll add a bit more advice here as well.

It might be easier to start off with the list of file names in a text file or a CSV (assuming the excel doc you are referring to is a XLSX format). It’ll be easier to learn. However, if it has to be an excel document I highly recommend looking into the ‘ImportExcel’ module by Doug Finke: dfinke/ImportExcel: PowerShell module to import/export Excel spreadsheets, without Excel (github.com). It will allow you to import the data really easily from an excel file and use it in Powershell using Import-Excel command. if it’s a text or csv file, Powershell has built in commands to handle those (Get-Content and Import-CSV are two I use pretty often).

The tasks end up being:

  1. Get the data into Powershell from the file.
  2. Iterate through each of the lines or objects to get your file name.
  3. take action (move) the file to the folder of choice). Perhaps confirm the file exists prior to moving.

So additional commands you may find helpful on your journey might be:

ForEach-Object
Move-Item
Test-Path
Get-Item

You can run Get-Help -Name Move-Item in a PowerShell window to learn more about that command. I also have teh tendency to just run Get-Help -Name Move-Item -Online or search for the command in Google to get to the online help page.

Hopefully this gets you started on your journey!

Thank you for the suggestions!