Link to home
Start Free TrialLog in
Avatar of ncomper
ncomper

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ncomper
ncomper

ASKER

That worked perfect thanks
Avatar of ncomper

ASKER

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
Avatar of ncomper

ASKER

Didn't mean to  to accept my own comment
Avatar of ncomper

ASKER

Excellent, worked perfect Thanks