troubleshooting Question

Copy files from old server to new server with Robocopy

Avatar of Steve Bona
Steve BonaFlag for Canada asked on
2 Comments1 Solution43 ViewsLast Modified:
I need to copy the old user directories to their new directory they are already using. In order not to mix the directories, I created a new sub-directory in each of the users' directories before making the copy.
So i write a little powershell script

$Importcsv = "C:\csv\MoveHomerDir.csv"
$HomeDirList = Import-csv $Importcsv

Foreach($HomeFolder in $HomeDirList){
$NewDir = "Migrate_Directory"
$CurrentDirPath = $HomeFolder.NewHomeDir
$NewDirPath = "$CurrentDirPath\$NewDir"
#Verify if new subfolder allready exist
If (Test-Path -Path $NewDirPath){
 Write-host "Directory $NewDir allready exist in $CurrentDirPath" -ForegroundColor Yellow

 Else {
 New-Item -Name $NewDir -Path $CurrentDirPath -ItemType Directory

#Start copy Directory
Foreach ($HomeDir in $HomeDirList) {
$HomeDirSource = $HomeDir.OldHomeDir
$HomeDirDest   = $HomeDir.NewHomeDir

robocopy "$HomeDirSource" "$HomeDirDest\$NewDir" /MIR /COPY:DATOU /LOG+:C:\Logs\TestMigrateHomeDirectory.log


My script works but copy directory seems to repeat itself, i don't understand why.
Did i forget something

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros