Script To move users home drive

Hi there i am looking for a tool/script to be able to run from  my workstation to be able to move a users home drive from one server to another.

So say their home drive was \\server1\homes\user1

I could type the users name in and it would show me that it is currently on server1 and then offer me a drop down list that i could select server2 server3 etc and then click a move button.

it would then update their AD with the new location and then move the data.

Any help would be appreciated.
Mark_MckieAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
here's the full script:
$name = Read-Host 'Enter user SamAccountName: (x to Abort)'
if($name -eq 'x'){return}
$user = (Get-ADUser -Filter {SamAccountName -eq $name}  | select 'HomeDirectory')
$homedir = [string]::Format("Current home Dir [{1}], {2}", $user.HomeDrive, $user.HomeDirectory, "Enter new home dir: (x to Abort)") 
Read-Host $homedir
if($homedir -eq 'x'){return}
write-output "Set$name HomeDirectory as $homedir"
Set-ADUser $name -HomeDirectory $homedir
write-output "Done"
$src = $user.HomeDrive
$dest = $homedir
write-output "copy $src to $dest"
gci $src -Recurse | Copy-Item -Destination $dest
write-output "Done"

Open in new window

0
 
Meir RivkinFull stack Software EngineerCommented:
i can give u a script which prompt u for user name, show u current hoe drive and allow u to change it (no drop down) by entering new server.
and it would be in powershell.
0
 
Mark_MckieAuthor Commented:
That sounds interesting.

May i have a look?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Meir RivkinFull stack Software EngineerCommented:
$name = Read-Host 'Enter user SamAccountName: (x to Abort)'
if($name -eq 'x'){return}
$user = (Get-ADUser -Filter {SamAccountName -eq $name}  | select 'HomeDirectory')
$msg = [string]::Format("Current home Dir [{1}], {2}", $user.HomeDrive, $user.HomeDirectory, "Enter new home dir: (x to Abort)") 
Read-Host $msg
if($msg -eq 'x'){return}
Set-ADUser $name -HomeDirectory $msg

Open in new window

0
 
Mark_MckieAuthor Commented:
Will this copy the data from one server to the other?
0
 
Meir RivkinFull stack Software EngineerCommented:
no, it would just update the AD HomeDirectory property.
0
 
Mark_MckieAuthor Commented:
Do you know of any script to then move the data after it has changed the home drive path?
0
 
Mark_MckieAuthor Commented:
Or could this script be amended.
0
 
Mark_MckieAuthor Commented:
0
 
Meir RivkinFull stack Software EngineerCommented:
i'll modify the script no problem.
0
 
Mark_MckieAuthor Commented:
Thank you very much Sedgwick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.