Solved

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

Posted on 2013-12-05
5
1,081 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 40

Accepted Solution

by:
footech earned 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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