[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Script to find all AD users with no Home Directory and set

Posted on 2013-12-05
5
Medium Priority
?
1,379 Views
Last Modified: 2013-12-05
Hi All

I have attempted to write a script to find all enabled users who have a null value for Home directory and then set one as we have a few hundred users who don't have one.

However I think my have a go mentality is greater than my powershell ability :)

$usersHD = Get-ADUser -Filter {(Enabled -eq "True")} -Properties * | Where-Object { $_.homedirectory -eq $null} 
 foreach ($user in $usersHD) 
{
set-aduser -homedrive u: -homedirectory - \\server\share\%username% 
}

Open in new window


I know line one works as if i look at the variable it lists all the users that do not have a Homedirectory, its the actual setting it that I cant get working

Can anyone help me out and explain were I am going wrong

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
5 Comments
 
LVL 41

Accepted Solution

by:
footech earned 2000 total points
ID: 39698023
It's the %username% part that doesn't work for you (also you weren't directing the set-aduser command at any identity so you should have gotten an error).  If I recall correctly, setting this through the GUI does a dynamic substitution.  Pretty sure you would have to set this explicitly for each user.
 
foreach ($user in $usersHD) 
{
set-aduser $user.samaccountname -homedrive u: -homedirectory "\\server\share\$($user.samaccountname)" 
}

Open in new window

0
 
LVL 5

Author Comment

by:ncomper
ID: 39698054
That worked perfect thanks
0
 
LVL 5

Author Comment

by:ncomper
ID: 39698132
I've requested that this question be closed as follows:

Accepted answer: 0 points for ncomper's comment #a39698054

for the following reason:

Excellent worked perfect Thanks
0
 
LVL 5

Author Comment

by:ncomper
ID: 39698131
Didn't mean to  to accept my own comment
0
 
LVL 5

Author Closing Comment

by:ncomper
ID: 39698133
Excellent, worked perfect Thanks
0

Featured Post

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

650 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