Solved

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

Posted on 2014-10-19
14
412 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 28

Expert Comment

by:becraig
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 28

Expert Comment

by:becraig
Comment Utility
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
Comment Utility
Your command does not appears to be working..
Capture.JPG
0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 56

Expert Comment

by:Cliff Galiher
Comment Utility
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
Comment Utility
Unfortunately it is still not working. I will try Googling it some more.
0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
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
Comment Utility
Without going into too much detail, I need to copy. Thanks for the link but I am already well aware of that.
0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
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 28

Accepted Solution

by:
becraig earned 500 total points
Comment Utility
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
Comment Utility
Hi Craig

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 to another domain controller. Log onto the new domain controller with a user account t…

744 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

8 Experts available now in Live!

Get 1:1 Help Now