I have a problem in a complex copy.
Below is an example of my script and CSV with source and destination paths. The powershell script I created works well in part but not totally, it makes the copies based on the CSV, however in the example we see the directories "2018", "2019", "2020", "2021", "2022" need to be copied to the destination directory "Archive" and the directory "2023" under the destination directory "Years", so far the script is doing its job.
CSV model
Source;Destination "\data.valampe.comInformation technologyRobotics DepartmentYears";"\data.valampe.comUITRobotics DepartmentYears" "\data.valampe.comInformation technologyRobotics DepartmentYears2018";"\data.valampe.comUITRobotics DepartmentYearsArchives2018" "\data.valampe.comInformation technologyRobotics DepartmentYears2019";"\data.valampe.comUITRobotics DepartmentYearsArchives2018" "\data.valampe.comInformation technologyRobotics DepartmentYears2020";"\data.valampe.comUITRobotics DepartmentYearsArchives2020" "\data.valampe.comInformation technologyRobotics DepartmentYears2021";"\data.valampe.comUITRobotics DepartmentYearsArchives2021" "\data.valampe.comInformation technologyRobotics DepartmentYears2022";"\data.valampe.comUITRobotics DepartmentYearsArchives2022" "\data.valampe.comInformation technologyRobotics DepartmentYears2023";"\data.valampe.comUITRobotics DepartmentYears2023" "\data.valampe.comInformation technologyRobotics DepartmentAI Lab";"\data.valampe.comUITRobotics DepartmentAI Lab" "\data.valampe.comInformation technologyRobotics DepartmentAI Lab2018";"\data.valampe.comUITRobotics DepartmentAI LabArchives2018" "\data.valampe.comInformation technologyRobotics DepartmentAI Lab2019";"\data.valampe.comUITRobotics DepartmentAI LabArchives2018" "\data.valampe.comInformation technologyRobotics DepartmentAI Lab2020";"\data.valampe.comUITRobotics DepartmentAI LabArchives2020" "\data.valampe.comInformation technologyRobotics DepartmentAI Lab2021";"\data.valampe.comUITRobotics DepartmentAI LabArchives2021" "\data.valampe.comInformation technologyRobotics DepartmentAI Lab2022";"\data.valampe.comUITRobotics DepartmentAI LabArchives2022" "\data.valampe.comInformation technologyRobotics DepartmentAI Lab2023";"\data.valampe.comUITRobotics DepartmentAI Lab2023"
Script model
`# Delete all existing variables Remove-Variable -Name * -ErrorAction SilentlyContinue
$date = Get-Date -Format "yyyy-MM-dd-HH-mm-ss"`
# Request Business name
$BUsinessLineName = Read-Host "Enter the Business name without space and without special characters"
# Path to CSV file containing source and destination information $csvPath = "E:powershell commandCopyMultifoldersMultifoldersEncryptedTest.csv"
# Read CSV file with specified delimiter (;) $csvContent = Import-Csv -Path $csvPath -Delimiter ";"
# Report name log $reportName = $BUsinessLineName + "_" + $date + "_Test.log" $sourcelogs = "E:powershell commandCopyMultifoldersLogs" + $reportName
# Create an associative array to store previously copied directories $copiedDirectories = @{}
# Browse each line of the CSV file and make the copy foreach ($row in $csvContent) {
`# Get source and destination paths for each line $sourcePath = $row.Source.Trim( " ) $destinationPath = $row.Destination.Trim( " )
Write-Host "Source: $sourcePath"
Write-Host "Destination: $destinationPath"`
# Check if the destination directory already exists if (Test-Path $destinationPath) { Write-Host "Skipping copy of directory: $sourcePath (already exists at $destinationPath)" continue }
# Check if the directory has already been copied to this destination if ($copiedDirectories.ContainsKey($destinationPath) -and $copiedDirectories[$destinationPath] -contains $sourcePath) { Write-Host "Skipping copy of directory: $sourcePath (already copied to $destinationPath)" continue }
# Copy source directory to destination chcp 1252 robocopy $sourcePath $destinationPath /E /r:0 /w:0 /XO /XJ /XJF /XD ~BROMIUM* /XF sourceonefilesmanifest* ~$*.* /LOG:$sourcelogs
# Check if the source directory copy was successful if (!(Test-Path $destinationPath)) { Write-Host "Failed to copy directory: $sourcePath" } else { Write-Host "Successfully copied directory: $sourcePath" # Add the copied directory to the table of copied directories if ($copiedDirectories.ContainsKey($destinationPath)) { $copiedDirectories[$destinationPath] += $sourcePath } else { $copiedDirectories[$destinationPath] = @($sourcePath) } } }
However, the parent source directories "Years" & "AI Lab" contain files which, unfortunately, are not copied. Another problem is that during incremental copies the source files/directories that could potentially be modified during the incremental copy phase are not updated at the destination. Could someone help me?