Link to home
Start Free TrialLog in
Avatar of Twhite0909
Twhite0909

asked on

Powershell script or cmd to search All Active User accounts in AD

I need a script or simple command to search ONLY user accounts and export it to a CSV.  I have run other scripts but they grab Service accounts, shared mailboxes, Resources, disabled accounts etc.. I just want Active Users within AD.  Any ideas?

Thanks
Avatar of Qlemo
Qlemo
Flag of Germany image

AD does not know which account is a resource or service account. You'll always have to query some add-on able to tell you that, e.g. for resources Exchange.
But I guess it is safe to assume enabled accounts with a given name are real users:
Import-Module ActiveDirectory
Get-ADUser -Filter "*" | ? { $_.Enabled -and $_.GivenName -ne "" }

Open in new window

Avatar of ja_foster
ja_foster

If your user accounts are separated from your mgmt. accounts in different OU's you can use the -searchbase switch to tell Get-ADUser where to search for your users. (Change the distinguishedName to your domain info). Then pipe it out to a csv.
Get-ADUser -Filter {Enabled -eq $True} -searchbase "OU=Users,OU=production,DC=contoso,DC=com" | Export-CSV \\server\share\enabledUsers.csv
Avatar of Twhite0909

ASKER

Get-ADUser -Filter {Enabled -eq $True} -searchbase "OU=Users,OU=production,DC=contoso,DC=com" | Export-CSV \\server\share\enabledUsers.csv

 that worked great.  Now theyre asking if I can add creation date, department?  Do you the syntax for those to add to this cmd?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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
Can I combine this with the other script to run.together?
The above is the complete script, as far as we know it.
But won't that just give me all all users again and not go to specific OU?  that's what I need and that's what the first command I got did it went to a specific oh you called locations where I have all of my office is this week just user accounts anything else. jared mailbox or service accounts things and I don't need to if I could put this - filter properties in with the original command somehow I can pull just use your accounts as well as their
Whats the full cmd to have AD search an OU and get the Users as well as creation date?