Solved

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

Posted on 2014-10-19
14
430 Views
Last Modified: 2014-11-19
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.
0
Comment
Question by:the_omnific
  • 6
  • 6
  • 2
14 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40391284
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
 
LVL 56

Expert Comment

by:Cliff Galiher
ID: 40391285
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
 
LVL 1

Author Comment

by:the_omnific
ID: 40391300
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
 
LVL 1

Author Comment

by:the_omnific
ID: 40391302
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
 
LVL 29

Expert Comment

by:becraig
ID: 40391307
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
 
LVL 1

Author Comment

by:the_omnific
ID: 40391316
Your command does not appears to be working..
Capture.JPG
0
 
LVL 29

Expert Comment

by:becraig
ID: 40391318
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
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 
LVL 56

Expert Comment

by:Cliff Galiher
ID: 40391323
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
 
LVL 1

Author Comment

by:the_omnific
ID: 40391328
Unfortunately it is still not working. I will try Googling it some more.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40391334
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
 
LVL 1

Author Comment

by:the_omnific
ID: 40391340
Without going into too much detail, I need to copy. Thanks for the link but I am already well aware of that.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40391347
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
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40435454
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
 
LVL 1

Author Comment

by:the_omnific
ID: 40453725
Hi Craig

The script didn't work to be honest however, I will assign you the points for your efforts.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now