Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Search Filter Syntax in Active Directory

Reply
Thread Tools

RE: Search Filter Syntax in Active Directory

 
 
Tim Golden
Guest
Posts: n/a
 
      09-30-2004
[Dirk Hagemann]
| 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.

<code>

import win32com.client

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")

</code>

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
through it).

<code>

import win32com.client

for domain in win32com.client.GetObject ("WinNT:"):
print domain.Name

</code>

Third example: list all the computers in a particular domain.
Again WinNT:// syntax.

<code>

import win32com.client
domain_name = "VOUK"
domain = win32com.client.GetObject ("WinNT://" + domain_name)
domain.Filter = ["Computer"]
for computer in domain:
print computer.Name

</code>

HTH
TJG

__________________________________________________ ______________________
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:
http://www.star.net.uk
__________________________________________________ ______________________
 
Reply With Quote
 
 
 
 
Dirk Hagemann
Guest
Posts: n/a
 
      10-01-2004
Tim Golden schrieb:
> [Dirk Hagemann]
> | 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.
>
> <code>
>
> import win32com.client
>
> 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")
>
> </code>
>
> 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
> through it).
>
> <code>
>
> import win32com.client
>
> for domain in win32com.client.GetObject ("WinNT:"):
> print domain.Name
>
> </code>
>
> Third example: list all the computers in a particular domain.
> Again WinNT:// syntax.
>
> <code>
>
> import win32com.client
> domain_name = "VOUK"
> domain = win32com.client.GetObject ("WinNT://" + domain_name)
> domain.Filter = ["Computer"]
> for computer in domain:
> print computer.Name
>
> </code>
>
> HTH
> TJG
>


Hi Tim!

The third example what is yet in use in my script - I asked for it some
month ago here It is a great help!

But now I need more than just the names of the computers, I need their
properties like OS, Service Pack, Version and stuff like this.

What I managed yet is to get the properties of an object if I know the
LDAP path of this object.
But in our AD-structure the computer-accounts are not all in the same OU
and the OUs could have another name from one day to the next day... So I
need to get all computers wherever they are with some of their properties.
I'll try your hints after the next week when I'm back at work - next
week I have a SQL-course

Dirk

 
Reply With Quote
 
 
 
 
Dirk Hagemann
Guest
Posts: n/a
 
      10-12-2004
Hi Tim!

I tried your first example and it works - after I noticed that I have
to change some CN in OU... That is also a mistake in some of my other
codes which I will try now.
Thanks for your help again!!!

Dirk

Tim Golden <> wrote in message news:<mailman.4128.1096533140.5135.python->...
> [Dirk Hagemann]
> | 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.
>
> <code>
>
> import win32com.client
>
> 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")
>
> </code>
>
> 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
> through it).
>
> <code>
>
> import win32com.client
>
> for domain in win32com.client.GetObject ("WinNT:"):
> print domain.Name
>
> </code>
>
> Third example: list all the computers in a particular domain.
> Again WinNT:// syntax.
>
> <code>
>
> import win32com.client
> domain_name = "VOUK"
> domain = win32com.client.GetObject ("WinNT://" + domain_name)
> domain.Filter = ["Computer"]
> for computer in domain:
> print computer.Name
>
> </code>
>
> HTH
> TJG
>
> __________________________________________________ ______________________
> 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:
> http://www.star.net.uk
> __________________________________________________ ______________________

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to filter Active Directory using objectGUID ? =?Utf-8?B?Unlv?= ASP .Net 0 10-19-2005 10:26 AM
Search-Filter for LDAP (MS Active Directory) Dirk Hagemann Python 3 10-15-2004 06:56 AM
Re: Search-Filter for LDAP (MS Active Directory) Ames Andreas (MPA/DF) Python 2 10-14-2004 08:21 PM
Active Directory Search fails ("The directory service is unavailab ejcosta ASP .Net Security 2 10-08-2004 09:57 AM
Search Filter Syntax in Active Directory Dirk Hagemann Python 0 09-29-2004 08:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57