Solved

Powershell script to set existing users Homedirectory based on inputfile

Posted on 2013-10-24
7
1,346 Views
Last Modified: 2013-10-29
Hi All

I have a list of users that have not got a home directory set, I have all the samaccountname in a CSV file,

I would like to use this as an input file to set the Home directory to use the H drive and be \\domain.com\userprofiles\%username%\Home

Is anyone able to help me out with a script to do that.

Thanks
0
Comment
Question by:ncomper
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39597351
Try this..
Import-Csv C:\users.csv | % {
Set-aduser $_.username -homedirectory "\\domain.com\userprofiles\$($_.username)\Home"
}

Open in new window

Input csv format..
username
UserA
UserB
UserC

Open in new window

0
 
LVL 5

Author Comment

by:ncomper
ID: 39597469
Thanks, that works but configures the local path section of the Home Folder

However I would like it to use the connect section where we choose a drive letter and specify the UNC path in the To field

Thanks
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39597547
Add parameter -homedrive "X:"

Import-Csv C:\users.csv | % {
Set-aduser $_.username -homedirectory "\\domain.com\userprofiles\$($_.username)\Home" -homedrive "X:"
}

Open in new window

0
 
LVL 5

Author Comment

by:ncomper
ID: 39597565
I managed to get it working using the following

Import-Csv C:\scripts\users.csv | % {Set-aduser -HomeDrive 'H:' $_.username -homedirectory "\\2008dc01\homefolders\$($_.username)"}

Open in new window


However I noticed it does not actually create the folder which if you do in the GUI it does.

Is there something I am missing?

Thanks
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39597763
I just checked.. you need to create the folders with in script itself...

Import-Csv C:\users.csv | % {
 $HomeDirectory = "\\domain.com\userprofiles\$($_.username)\Home" 
  Set-aduser $_.username -homedirectory $HomeDirectory -homedrive "X:"
  New-item –path $HomeDirectory -type directory -force
}

Open in new window


Ref : http://blogs.technet.com/b/heyscriptingguy/archive/2013/06/04/creating-a-home-drive-with-windows-powershell-part-1.aspx
0
 
LVL 5

Author Comment

by:ncomper
ID: 39600251
Thanks, ill take a look, seems as though to get the permissions sorted is fairly complex
0
 
LVL 5

Author Closing Comment

by:ncomper
ID: 39608533
Thanks
0

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

762 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

18 Experts available now in Live!

Get 1:1 Help Now