Copy from different sources to different destinations

Here is a script that will help you copy from different sources to different destinations. Like when you need to create a new structure for your fileserver.

You need to create a csv file, with the source, destination, and excluded folders. Leaver the latter empty if you shouldn’t exclude anything.

The script search through all csv files located in subfolder SupportFiles. The script below requires semicolon as delimiter, if you want to exlude more than one subfolder you should be able to that with a space between the paths

#checks your current location of the scriptfile and searches for files to import in subfolder Supportfiles
$filedir = Join-Path -Path (get-location) -ChildPath 'SupportFiles'
$csvfiles =  $filedir| get-childitem | where {$ -like "*.csv"}

foreach ($file in $csvfiles) {
$records = import-csv $file.fullname -header source,destination,exclude -delimiter ";" -Encoding utf8
$logfile = "E:\Robocopylog\RolleBaseretAuth"+$($ -replace ".csv")+".log"
Foreach ($item in $records) {

$item.source  + ";" +  $item.destination + ";" + $item.exclude

if($item.exclude) {
robocopy $item.source $item.destination /XD $item.exclude /E /ZB /X /PURGE /COPY:DAT /TEE /R:3 /W:3 /LOG+:$logfile
else {
robocopy $item.source $item.destination /E /ZB /X /PURGE /COPY:DAT /TEE /R:3 /W:3 /LOG+:$logfile

### Copy Profiles

robocopy F:\Profiles G:\Profiles /mir /XD "*Recycle.Bin*" /sec /secfix /copyall /R:3 /W:3 /B /TEE /log+:E:\Robocopylog\RolleBaseretAuthProfiles.log


Was this helpful please rate 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)