We help IT Professionals succeed at work.
Get Started

Copy files from old server to new server with Robocopy

Steve Bona
Steve Bona asked
on
40 Views
Last Modified: 2020-03-23
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

CopyHomeDirectoryCSVFileRobocopyLog
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE