Move Redirected User Documents to a new folder location at a different folder level

StackOverflow https://stackoverflow.com/questions/18026949

  •  21-06-2022
  •  | 
  •  

سؤال

Our company is in the middle of a server transition. I am need some help with a little bit of an issue i ran into.

First off. Or existing domain is using Folder Redirection for their "My docs" etc. The original setup was done to the users home folder. ( ex. \server1\users\%username%*.* )

We are migrating everything over to a entirely new domain. Use accounts were created from sratch instead of migrated. We do need to move all the user documents to the associated folders. The usernames are identical but the location is differently laid out ( ex. \server2\users\%username%\My Documents*.* ) Basically we created a folder within their home folder to house their documents. This was mainly because of the whole "My documents" labeling that shows with Windows 7 as well as easy way to differentiate the folder on Mac systems.

So I started using RichCopy to push the files manually entering each users source and destination since they did not match. Does anyone have a way i could make it so that it has a certain variable to account for.

In theory: \server1\users\%username%\ moves to \server2\users\%username%\My Documents\

The variable would search the usernames, match them up, and push automatically for every folder within \users\

Any type of GUI interface program or even a powershell script that i can manipulate a little would be super helpful. I can't see doing this manually for each user, we have around 1000 users.

I great appreciate any help ahead of time!

So far I have been working with Powershell to run Robocopy to perform this action. I am trying to make the powershell pull the usernames from a csv and input it into the robocopy string. Here is my code:

    $usernames = import-csv c:\scripts\usernames.csv


 foreach($user in $username)

   {

    $field1 = $user.username


   Echo "$field1"

   }

$source = "\\server03\Staff-MyDocs\$user"
$destination = "\\server3\users$\Staff\$user\My Documents\"

robocopy $source $destination /S /E /COPY:DATSOU /R:1 /W:5 >C:\scripts\HomeDir_robocopy.log

Any better ideas to make this work??

هل كانت مفيدة؟

المحلول

According to your description this should work:

$csv = 'C:\scripts\usernames.csv'
$log = 'C:\scripts\HomeDir_robocopy.log'

Import-Csv $csv | % { $_.username } | % {
  $src = "\\server1\Users\$_"
  $dst = "\\server2\Users\$_\My Documents\"

  robocopy "$src" "$dst" /e /copyall /r:1 /w:5 /log+:"$log"
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top