Export list of users who have specific unc path in home folder attribute

Hi All

I am looking for a script that can search our domain and export only users that have \\server01\Users\ in the path for the Home folder attribute  (Not Local Path)

If it could export the SamAccountName, full Homefolder path and the chosen drive letter thats in the drop down

Our AD is Windows 2003 level with all DC's at Win 2003 SP2 (not R2)

Is this possible


Who is Participating?
Farhan KaziConnect With a Mentor Systems EngineerCommented:
On Windows 2003 command-line copy and paste following line. This will generate UserList.txt file on C drive root.

Above statement uses Windows 2003 built-in tool called DSQuery thus does not require Powershell or any third-party executable.

Hope this helps!

DSQuery * -Filter "(&((objectCategory=Person)(objectClass=User)(homeDirectory=\\server01\Users\*)))" -Attr samAccountName Name -Limit 0 >UserList.txt

Open in new window

I would suggest trying joeware's adfind (www.joeware.net) although you may need to export the attributes for all into excel and sort in excel. Have a look though as I remember it was a really powerful tool last time I used it...
If you can use powershell, here is the scripts you need:

First type this
import-module ActiveDirectory

Press Enter

Now cut and pastes this:

Get-ADUser -Filter * -SearchBase "DC=YOUR_DOMAIN,DC=COM" -Properties * | Select-Object SamAccountName,GivenName,Surname,DisplayName,HomeDirectory | export-csv -path AllADUsers_v3.csv -NoTypeInformation -Encoding "UTF8"

Change the DC line to match your domain.

Open up your cvs vile, make a filter on the first line and then you can sort the HomeDirectory field.
ncomperAuthor Commented:

You got me on the right path, when i ran that it wasnt displaying correctly but i modified it to the below and its working well

DSQuery * -Filter "(&((objectCategory=Person)(objectClass=User)(homeDirectory=\5c\5cserver01\5cusers\5c*)))" -Attr samAccountName Name homeDirectory -limit 0 >c:\Users.txt

Thanks again

ncomperAuthor Commented:
DSQuery * -Filter "(&((objectCategory=Person)(objectClass=User)(homeDirectory=\5c\5cserver01\5cusers\5c*)))" -Attr samAccountName Name homeDirectory -limit 0 >c:\Users.txt

Modified slightly to this but 99.99% there.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.