Solved

Powershell script to set existing users Homedirectory based on inputfile

Posted on 2013-10-24
7
1,441 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
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…

756 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