User profile migration

nav2567
nav2567 used Ask the Experts™
on
Hello

I am trying this command to copy profile of users only in my text file from an old server to a new server, and I am getting %%i was unexpected error.  

for /f %%i in (userprofiles_v1.txt) do robocopy.exe "\\oldserver\userprofiles\%%i" \\newserver\userprofiles /MIR /COPY:DATSO /W:5 /R:10 /V /LOG:C:\users.log

Would someone advise how to correct?

Please advise if there is a better way.  What is the equivalent command in powershell (if using powershell is better) ?


Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
robocopy will work just fine.
You're probably pasting that directly into a command prompt; then you only need one percent sign for the loop variable.
In addition, you need the target folder as well.
The version with two is required when running it as a batch file.
Command prompt:
for /f "delims=" %i in (userprofiles_v1.txt) do robocopy.exe "\\oldserver\userprofiles\%i" "\\newserver\userprofiles\%i" /MIR /COPY:DATSO /W:5 /R:10 /V /LOG:C:\users.log

Open in new window

Batch:
for /f "delims=" %%i in (userprofiles_v1.txt) do robocopy.exe "\\oldserver\userprofiles\%%i" "\\newserver\userprofiles\%%i" /MIR /COPY:DATSO /W:5 /R:10 /V /LOG:C:\users.log

Open in new window

Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
For the sake of completeness, the PowerShell equivalent:
Get-Content -Path userprofiles_v1.txt | ForEach-Object {robocopy.exe "\\oldserver\userprofiles\$_" "\\newserver\userprofiles\$_" /MIR /COPY:DATSO /W:5 /R:10 /V /LOG:C:\users.log}

Open in new window

Author

Commented:
Excellent.  Thank you very much for your help again!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial