?
Solved

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

Posted on 2013-12-05
5
Medium Priority
?
1,279 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 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
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…
Suggested Courses

762 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