Skip to content

Instantly share code, notes, and snippets.

@jonimattila
Created February 9, 2017 09:01
Show Gist options
  • Save jonimattila/cbee64bbd6cdd91adbcb515e47df34b7 to your computer and use it in GitHub Desktop.
Save jonimattila/cbee64bbd6cdd91adbcb515e47df34b7 to your computer and use it in GitHub Desktop.
#Import CSV file, commas as separators, headers are Path, Username
$Csv = Import-Csv C:\temp\file.csv
#Separate headers
foreach ($Line in $Csv) {
#Separate Path header for old user home folder
$UserHome_old = $Line.Path
#Separate Username header for new home folder location
$UserHome_new = "\\server\users1$\" + $Line.Username
$corpaccount = "DOMAIN\" + $Line.Username
#Robocopy switches, Backup mode, Copy Subdirs, Copy all file information, Write status output to console and log, Multithread 128, Verbose logging
$switches = ("/B", "/e", "/r:1", "/copyall", "/TEE", "/MT:128", "/V", "/log:C:\temp\$Line.Username.txt")
#Copy folder from old location to new location
& robocopy $UserHome_old $UserHome_new $switches
#Modify H: directory in AD
Set-ADuser -Identity $Line.Username -HomeDrive "H:" -HomeDirectory "$UserHome_new"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment