Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

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.
0
the_omnific
Asked:
the_omnific
  • 6
  • 6
  • 2
1 Solution
 
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
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
 
the_omnificAuthor Commented:
Hi Craig

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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now