Solved

Powershell script to set existing users Homedirectory based on inputfile

Posted on 2013-10-24
7
1,374 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
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…

770 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