PowerTip: Find List of Users in Active Directory


Summary: Use the Filter parameter in the Active Directory module.

Hey, Scripting Guy! Question I was playing with the Active Directory cmdlets and noticed that they seem to need the Distinguished Name.
           Is there any way to find users instead of supplying this very explicit object each time?

Hey, Scripting Guy! Answer Use the –Filter parameter to pull the information. For example, to find all users with the last name Smith,
           specify the Surname attribute with the –Filter parameter:

GET-ADUser –filter 'Surname –eq "Smith"' 

Comments (8)

  1. @Ed

    …and for this I am still the student Oh wise and wonderful Master of Scripting 🙂

    Sean

  2. @Sean @Ed

    Agreed, hard to beat LDAP, but get-adgroupmember and get-aduser combined with simple filters seems to catch 95% of what I need to do these days. Perhaps they’ve made me lazy though. 🙂

  3. @Anthony

    Before PowerShell I used to play with the Query command in Active Directory Users and Computers. It worked well too. But with PowerShell and simple parameters it made a lot more sense to me 🙂

    Cheers!
    Sean

  4. That’s one of my favorites, combine this with another PowerShell command or two and that ability to modify large groups of users is easy.

  5. Ed Wilson says:

    @Sean Kearney (Honorary Scripting Guy) For more complex things, I still use the LDAP query syntax. For one thing, they are easy to port from one language to another, and for another, I have already written them and they just need minor tweaking to make
    them work in PowerShell. But for simple things, -FIlter rocks.

  6. Ghazipur khabar says:

    thanks for shearing it….
    http://ghazipurkhabar.co.in/

Skip to main content