Solved

Script To move users home drive

Posted on 2013-05-13
11
329 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
Technology Partners: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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