PowerShell to copy selected Files

Posted: October 10, 2018 in Curious, Dev enviroment, Development Tools, Powershell, Windows 8, Windows 8.1, Windows Phone 8

In the last months i had been working on a project that had require that to solve some issues to build a lot off simple tools to help us achieve a new milestone.

Today i had a new simple need and find a lot of troubles to get an answer. I had just to copy some images to a new folder from a vast universe.

This little tool should run on a production server. Powershell comes to the rescue, but i had a lot off trouble to get a spinet for my problem.

So here the way i solve this:

1st: identify the files i want to copy and get a kind off database for that, we had create a CSV file for that with the following struture



2st create a folder where i will save the copying files

3st Iterate for each line of the YourFileName column and copy each file for the destiny folder

what i need to know to do this:

  • How to load the CSV file fot powershell consumption, this can be made by the command ‘Import-Csv fileList1.csv’ this will load into memory the whole file
  • How to read each line, since we had the need to create a cycle we can use the following instruction ForEach { }
  • Define the intended action for each row in the CSV file

The result of this comes in the fantastic line of code

Import-Csv fileList1.csv | ForEach {Copy-Item “c:\AllFilesUniverse\$($_.YourFileName)” f:\SelectedFiles }

We now just have to open the Windows powershell

and execute or command, a special attention in order for the command work we should runit on c:\ otherwize we need to put the full path for the csv file





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s