Solved

Script To move users home drive

Posted on 2013-05-13
11
324 Views
Last Modified: 2013-05-14
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.
0
Comment
Question by:Mark_Mckie
  • 6
  • 5
11 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39161575
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
 

Author Comment

by:Mark_Mckie
ID: 39161584
That sounds interesting.

May i have a look?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39161690
$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
 

Author Comment

by:Mark_Mckie
ID: 39163808
Will this copy the data from one server to the other?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39163816
no, it would just update the AD HomeDirectory property.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Mark_Mckie
ID: 39163828
Do you know of any script to then move the data after it has changed the home drive path?
0
 

Author Comment

by:Mark_Mckie
ID: 39163829
Or could this script be amended.
0
 

Author Comment

by:Mark_Mckie
ID: 39163836
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39163867
i'll modify the script no problem.
0
 

Author Comment

by:Mark_Mckie
ID: 39163887
Thank you very much Sedgwick
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39163904
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now