Solved

Script To move users home drive

Posted on 2013-05-13
11
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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