Search Filter Syntax in Active Directory
tim.golden at viacom-outdoor.co.uk
Thu Sep 30 10:27:53 CEST 2004
| I want to get the properties of all the computer-accounts of an
| ActiveDirectory structure (Microsoft). I know that could be done by
| using "Search Filter Syntax" with LDAP-Dialect or SQL-Dialect.
| I found a lot of information about these dialects, but no
| example how to use this in an python-script.
| Does anybody have a simple example for me, how to get some
| information out of AD?
I twitch nervously every time I have to pull something
out of AD, but hopefully a couple of working examples
might get you going. In general, anything you see elsewhere
in VBS etc. can be done with a couple of GetObject-type
calls in win32com.client.
First example: find the display name of a user, given a user name.
This one uses the LDAP:// moniker syntax.
username = "goldent"
ldap_string = "LDAP://cn=%s,cn=users,dc=gb,dc=vo,dc=local" % username
ldap_me = win32com.client.GetObject (ldap_string)
print username, "=>", ldap_me.Get ("displayName")
Second example: find all the domains known by this workstation/server.
This example uses the WinNT:// object, which I personally find
a lot easier / more intuitive to use, so long as it meets your
need (it doesn't do everything, and I'm not sure you can update
for domain in win32com.client.GetObject ("WinNT:"):
Third example: list all the computers in a particular domain.
Again WinNT:// syntax.
domain_name = "VOUK"
domain = win32com.client.GetObject ("WinNT://" + domain_name)
domain.Filter = ["Computer"]
for computer in domain:
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
More information about the Python-list