Solved

Powershell script to set existing users Homedirectory based on inputfile

Posted on 2013-10-24
7
1,458 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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

Featured Post

Office 365 Training for IT Pros

Learn how to provision Office 365 tenants, synchronize your on-premise Active Directory, and implement Single Sign-On.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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 walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

740 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