Solved

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

Posted on 2014-10-19
14
532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 58

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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 
LVL 58

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

630 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