Solved

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

Posted on 2015-01-14
8
155 Views
Last Modified: 2015-03-06
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
0
Comment
Question by:Twhite0909
[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
  • 3
8 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 40549343
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

0
 

Expert Comment

by:ja_foster
ID: 40549996
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
0
 

Author Comment

by:Twhite0909
ID: 40553700
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?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40553773
Those are not part of the "default" property set of Get-ADUser, so we have to ask for them:
Get-ADUser -Filter {Enabled -eq $True} -searchbase "OU=Users,OU=production,DC=contoso,DC=com"  -Property Created, Department |
  Export-CSV \\server\share\enabledUsers.csv 

Open in new window

When using Get-ADUser -filter * -Property * you will get all available properties.
0
 

Author Comment

by:Twhite0909
ID: 40554074
Can I combine this with the other script to run.together?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40554099
The above is the complete script, as far as we know it.
0
 

Author Comment

by:Twhite0909
ID: 40554188
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
0
 

Author Comment

by:Twhite0909
ID: 40554313
Whats the full cmd to have AD search an OU and get the Users as well as creation date?
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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