Skip to content

Instantly share code, notes, and snippets.

@dpritchett
Created November 17, 2010 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpritchett/703567 to your computer and use it in GitHub Desktop.
Save dpritchett/703567 to your computer and use it in GitHub Desktop.
find users named 'wes' in your AD
import clr
clr.AddReference('System.DirectoryServices')
from System.DirectoryServices import (
DirectorySearcher,
DirectoryEntry
)
filter = "(&(objectCategory=person)(objectClass=user)(givenName=wes*))"
search = DirectorySearcher(filter)
for result in search.FindAll():
entry = result.GetDirectoryEntry()
print "Name:", entry.Properties["givenName"].Value, entry.Properties["sn"].Value, \
"Email:", entry.Properties["mail"].Value, "Phone:", entry.Properties["telephonenumber"].Value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment