Avatar of MJB2011
MJB2011
 asked on

Powershell command to query AD home Dir users

I had this question after viewing Powershell - Export to CSV not working.

Having found the correct command and means of exporting it, Ive just discovered that the data isnt completely accurate. Ive just cross referenced some of the accounts that the the export has empty cells for the Home Directory but the user in AD has got one.

Any reason for this? This data now looking useless to me!
PowershellActive Directory

Avatar of undefined
Last Comment
asavener

8/22/2022 - Mon
asavener

Make sure you're connecting to the right domain controller via the powershell command; it's possible that one or more of your DCs aren't synchronizing properly.
nashiooka

If you want to lock into a particular DC you can user the -Server parameter on the Get-ADUser cmdlet.  In those cases I usually focus in on the PDC Emulator for a variety of reasons.

Code would be something like below, combining with previous question:

$DC = (Get-ADDomain).PDCEmulator
$Props = `
@(
 "scriptpath"
 "homedrive"
 "homedirectory" 
 )

Get-ADUser -Filter * -Properties $Props -Server $DC| 
Export-Csv -NoTypeInformation -Path C:\temp\users.csv

Open in new window

MJB2011

ASKER
only 2 DC's on domain both are on the same site. I have checked both DC's each chowing correct info on user.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
nashiooka

Can you conjure up an example of the inconsistency?
MJB2011

ASKER
Why do I need to change the command. Its inaccurate not incorrect data its bringing back.
MJB2011

ASKER
Yes I can. in the output data the users it captures with home Directories is correct, however the data is incorrect as there are users are no of in AD that have home directories that are not showing up.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
asavener

Are you always exporting to the same file name?  If it's locked, the export will fail and you will keep seeing the same data over and over.
MJB2011

ASKER
No recreating every time. plus the data hasn't changed since starting today.
asavener

What happens if you just try to query one of the users that are missing?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
MJB2011

ASKER
OK. I ran the same command on teh other DC and it brought back the correct result. Yes both report same data.
nashiooka

You mean there are users you know have home directories that are not showing up in the report?  If so you should check a few of them manually through Active Directory Users & Computers.  Consider that there are other ways to map home folders like net use .../home.

It's very unlikely Get-ADUser is missing something that matches the query.

Let me know what you find.
MJB2011

ASKER
I run the command on DC01 it brings back wrong results

I run on DC02 it brings back the right results.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
asavener

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.