Solved

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

Posted on 2013-12-05
5
944 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
  • 4
5 Comments
 
LVL 39

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Set OWA language and time zone in Exchange for individuals, all users or per database.
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now