Simple Powershell Script to Copy User Home Drives.

testmig.txttestmig.txtI'm writing a script that should be used for user migrations from one directory to another using powershell and robocopy. I have the paths I need to copy the users from and to and a CSV with the old usernames and new user names in seperated by "',". This is a pretty simple task but I am a powershell noob and am struggling to get it working.

I need to be able to customise the source and destination locations in the script for now I am using simply, c:\test\source and c:\test\dest. My attempt at making this work is attached. Please have a look and let me know where I'm going wrong. Only Newer files should be copied across each time so the script can be run multiple times during the migration and just pick up newer files the users may have added.

Thanks.
Darkheart-ITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical Specialist/DeveloperCommented:
Missing attachment
0
Darkheart-ITAuthor Commented:
Thanks, the board blocked the script because it had the Powershell extension, I've changed it to .txt and it's happy now. The list of users in the CSV is simply in the format:
 "SourceFolder1,DestinationFolder1
   SourceFolder2,DestinationFolder2"
etc.
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Open it in Notepad and paste the text here in a code block
0
dsuyemotoCommented:
The robocopy parameters are incorrect in the script file.  Here is a modified version:

$csvFile = 'c:\temp\test.csv'
$srchome = 'c:\temp\source'
$dsthome = 'c:\temp\dest'
$logfile = '.\copy.log'

Import-Csv $csvFile -Delimiter ',' |
    ForEach-Object {              
        RoboCopy $srchome $dsthome $_.Source /z /e /np /MIR /COPY:DAT /r:10 /w:40 /XO /IS /log+:$logFile
        $srcDoc = "{0}\{1}" -f $srcHome,$_.Source
        $dstDoc = "{0}\{1}" -f $dstHome,$_.Source
        Write-Host "$srcDoc,$dstDoc" -ForegroundColor green
        rename-item -Path "$dstDoc" -NewName $_.Destination
    }

NOTE: the $dstDoc using the $.Source is not a typo, I re-purposed it to use in the rename-item, because I didn't see a way to rename through robocopy.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dsuyemotoCommented:
Question has been answered
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.