# File Copy to Multiple locations Using a CSV File

**URL:** <https://forums.powershell.org/t/file-copy-to-multiple-locations-using-a-csv-file/3483>\
**Category:** PowerShell Help\
**Created:** [December 4, 2014, 7:47am UTC](https://forums.powershell.org/t/file-copy-to-multiple-locations-using-a-csv-file/3483 "2014-12-04T07:47:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [December 4, 2014, 7:47am UTC](https://forums.powershell.org/t/file-copy-to-multiple-locations-using-a-csv-file/3483/1 "2014-12-04T07:47:41Z")

</div>

I am currently scanning a directory and matching file names and then copying them to various file share locations (each file will have multiple desitnations). I am hard coding the locations and would like to instead store these locations in a csv file. The csv file should have 2 fields. , the destination column = path for the copy; and the string column = to identify the file file to be copied

heres what I am doing now

```
#Find and Move
$entries = Get-ChildItem $filepath 
foreach ($entry in $entries) {

$Gen2 = 'C:\Lab\Gen2'
$Billing = 'C:\Lab\Billing'
$PdgMtnService = 'C:\Lab\PdgMtnService'

if ($entry.FullName -like '*MOTION TO COMPEL*'){ copy-item -Path $entry.FullName -Destination $Billing -Force }
if ($entry.FullName -like '*MOTION TO COMPEL*'){ copy-item -Path $entry.FullName -Destination $Gen2 -Force }
if ($entry.FullName -like '*MOTION TO COMPEL*'){ copy-item -Path $entry.FullName -Destination $PdgMtnService -Force } 
}
```

thank you in advance

---

<div class="post-metadata">

**Author:** ![duffwv](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@duffwv](https://forums.powershell.org/u/duffwv)\
**Post date:** [December 4, 2014, 8:03am UTC](https://forums.powershell.org/t/file-copy-to-multiple-locations-using-a-csv-file/3483/2 "2014-12-04T08:03:47Z")

</div>

Maybe something like this:

```
$csv = Import-Csv -Path "T:\46\files.csv"
$filepath = "T:\46\src"
$entries = Get-ChildItem $filepath
ForEach ($entry in $entries) {
    $destinations = $csv | 
    Where-Object {$_.file -eq $entry.FullName} | 
    Select-Object -ExpandProperty destination
    ForEach ($destination in $destinations) {
        Copy-Item $entry.FullName $destination
    }
}
```

And a csv like:

“file”,“destination”  
“t:\46\src\New Text Document.txt”,"t:\46\dest\a"  
“t:\46\src\New Text Document.txt”,"t:\46\dest\b"  
“t:\46\src\New Text Document (2).txt”,"t:\46\dest\c"  
“t:\46\src\New Text Document (2).txt”,"t:\46\dest\d"

---

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [December 4, 2014, 8:24am UTC](https://forums.powershell.org/t/file-copy-to-multiple-locations-using-a-csv-file/3483/3 "2014-12-04T08:24:54Z")

</div>

Thank you for the response!

The copy part is perfect! But i need the csv 2 have only 2 columns “Strng2Fing” and “destination”

I need to incorporate the “Strng2Fing”

```
if ($entry.FullName -like ‘_MOTION TO COMPEL_’){ copy-item -Path $entry.FullName -Destination $Billing -Force }
```

And a csv like:

“Strng2Fing” ,“destination”

“MOTION TO COMPEL” , "t:\46\dest\a"  
“MOTION TO COMPEL” , "t:\46\dest\b"  
“MOTION TO COMPEL” , “t:\46\dest\ac”

find 1 file copy to 3 different locations

---

<div class="post-metadata">

**Author:** ![imessage357\_h1](https://avatars.discourse-cdn.com/v4/letter/i/91b2a8/32.png) [@imessage357\_h1](https://forums.powershell.org/u/imessage357_h1)\
**Post date:** [December 4, 2014, 1:46pm UTC](https://forums.powershell.org/t/file-copy-to-multiple-locations-using-a-csv-file/3483/4 "2014-12-04T13:46:44Z")

</div>

I Solved it

```
$csv = Import-Csv -Path "C:\Users\jcool\Documents\Test.csv"
$filepath = 'c:\test'
Get-ChildItem $filepath | foreach {
 $criteria = $csv
 $find = $csv | select -ExpandProperty find
    #Write-Host $_.fullname
    $a = $_.fullname
ForEach ($f in $find) {
    If ($a -like "*$f*") {

ForEach ($c in $criteria) {

Copy-Item $_.fullname $c.Destination

}
}
    }
      }
```

And a csv like

“Find”, “Destination”  
“Don Jones” , “c:\test\a”  
“Don Jones” , “c:\test\b”

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/file-copy-to-multiple-locations-using-a-csv-file/3483/5 "2024-05-16T20:46:42Z")

</div>

Closed on May 16, 2024, 8:46pm UTC


