Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell script to set existing users Homedirectory based on inputfile

Posted on 2013-10-24
7
Medium Priority
?
1,551 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
[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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 2000 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
Here's a look at newsworthy articles and community happenings during the last month.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

662 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