Script to copy existing redirected all users 'Desktop' folder to another location

I am looking for help with a script that will copy all our users existing redirected 'Desktop' folder (and contents) to another network location whilst keeping the folder permissions;
 
Please note that the 'Desktop' folder does not currently exist  on the destination.
 
The locations are as follows;
 
Source
\\SERVER\data$\Folder redirection\%username%\desktop
 
Destination
\\SERVER\%username%$\
 
Thank you.
LVL 1
the_omnificAsked:
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.

becraigCommented:
Robocopy should be able to do this for you:

gc userlist.txt | %{
ROBOCOPY "\\SERVER\data$\Folder redirection\$_\desktop" "\\SERVER\$_`$\" /MIR /SEC 
}

Open in new window

0
Cliff GaliherCommented:
The script is relatively trivial, but since you mentioned folder redirection, it is worth noting that changes to the policy will copy data on its own. And pre-seeding will not work as you expect and can, in fact, cause serious problems. If that is your goal, I recommend simply updating the policy and letting the data get copied by group policy as users log in.
0
the_omnificAuthor Commented:
Um thanks for your script Craig but I am receiving the following error; ERROR 5 (0x00000005) Accessing Destination Directory I am running this script as a Domain Admin.
 
Any ideas?
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

the_omnificAuthor Commented:
Hi Cliff

Folder redirection in GPO is no coping the data. It is configured to 'Redirect to the following location'. The person who initially configured the policy had redirections to other servers so I'm consolidating it all. .
0
becraigCommented:
I am guessing the destination directory needs to be created through the admin share, if the destination directory does not as yet exist:

gc userlist.txt | %{
if  (!(Test-Path \\SERVER\$_`$) {mkdir "\\SERVER\$_`$"}
ROBOCOPY "\\SERVER\data$\Folder redirection\$_\desktop" "\\SERVER\$_`$\" /MIR /SEC 
}
                     

Open in new window


Also there is a blog on this issue if above does not resolve this for you:
http://www.luisrocha.net/2008/12/robocopy-error-error-5-0x00000005.html
0
the_omnificAuthor Commented:
Your command does not appears to be working..
Capture.JPG
0
becraigCommented:
Missed a parentheses.
gc userlist.txt | %{
	if (!(Test-Path \\SERVER\$_`$)) { mkdir "\\SERVER\$_`$" }
	ROBOCOPY "\\SERVER\data$\Folder redirection\$_\desktop" "\\SERVER\$_`$\" /MIR /SEC
}

Open in new window

0
Cliff GaliherCommented:
Folder redirection absolutely *does* copy data. It does not *sync* data, but it does copy it. The reasoning behind it is so that if an admin turns on the policy in an environment, existing users don't see their data "disappear" when the redirection kicks in and the destination is no longer local. The first time the policy is applied, data is copied from local to the new destination.

A side effect of this behavior is that anytime the location changes, whether from local to a redirected destination, or from one redirected destination to another, the data will be copied from the old location to the new. You can, in fact, find horror stories of failed file server migrations where the old server was retired too soon and the GPCSE won't update the policy on the workstation because it cannot reach the old destination to perform the data migration.

This feature has been around over a decade. It cleans up after itself very well. Truly. Simply change the path and it will copy the data to the new destination for you. Test lab it if you like.
0
the_omnificAuthor Commented:
Unfortunately it is still not working. I will try Googling it some more.
0
becraigCommented:
Here is a good link for setting up the redirection.
http://www.virtualizationadmin.com/articles-tutorials/terminal-services/performance/configure-folder-redirection.html

This should work and eliminate the need to copy.
0
the_omnificAuthor Commented:
Without going into too much detail, I need to copy. Thanks for the link but I am already well aware of that.
0
becraigCommented:
What error did you have with the last version of the script when you ran it ?


The expectation should be:
1: get content of a list of usernames
2. Test the destination path if the folder exists, if it does not then create a folder username$
3. Run robocopy to copy files and security details.
0
becraigCommented:
Do you still need any help on this  ?

Your last error indicated a problem accessing the directory, I suspect that should be resolved with the  last script provided.
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
the_omnificAuthor Commented:
Hi Craig

The script didn't work to be honest however, I will assign you the points for your efforts.
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.