I am have trouble finding a simple working example of using ADO to search
Active Directory. I am hoping someone could point me to a generic working
script that connects to AD and pulls up a recordset to help me get started
into the right direction in learning ADO, ADSI on Python. 10 4350
Thanks but I was looking more for ADO com object than ADSI or ldap.
For some strange reason it is very hard to locate any working scripts that
use ADO to connect and search AD. Is there an issue with ADO and python
when connecting to AD?
I have try to build one myself with no luck. I think my problem is with
adodb.command calls.
Thanks for your response.
"alex23" <wu*****@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com... Heya,
There are a couple of examples on the O'Reilly site. These two are taken from 'Active Directory Cookbook', the first uses a COM object while the second uses a native LDAP module:
http://www.rallenhome.com/books/adco...thon_com.py.tx
t
http://www.rallenhome.com/books/adco...thon_ldap.py.t
xt This might give you a start.
- alex23
Here's a short example that uses ADO to search for a
user by wildcard.
import win32com.client
c = win32com.client.Dispatch("ADODB.Connection")
c.Open("Provider=ADSDSOObject")
rs,rc=c.Execute("""
SELECT adspath, title, name
From 'LDAP://DC=yourdomain, DC=COM'
where objectClass='user' and name='Roger*'
""")
while not rs.EOF:
for f in rs.Fields:
print f.Name, f.Value
rs.MoveNext()
hth
Roger
"LittlePython" <Li**********@lost.com> wrote in message
news:56aJf.78250$_D1.4370@trnddc03... Thanks but I was looking more for ADO com object than ADSI or ldap. For some strange reason it is very hard to locate any working scripts that use ADO to connect and search AD. Is there an issue with ADO and python when connecting to AD? I have try to build one myself with no luck. I think my problem is with adodb.command calls.
Thanks for your response.
"alex23" <wu*****@gmail.com> wrote in message news:11*********************@f14g2000cwb.googlegro ups.com... Heya,
There are a couple of examples on the O'Reilly site. These two are taken from 'Active Directory Cookbook', the first uses a COM object while the second uses a native LDAP module:
http://www.rallenhome.com/books/adco...thon_com.py.tx t http://www.rallenhome.com/books/adco...thon_ldap.py.t xt This might give you a start.
- alex23
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
To be more clear, something like this example but in python. I have tryed to
convert something very simular to this
but have failed.
------ SCRIPT CONFIGURATION ------
strBase = "<LDAP://<BaseDN>>;"
strFilter = "<Filter>;"
strAttrs = "<AttrList>;"
strScope = "<Scope>"
' ------ END CONFIGURATION ---------
set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
set objComm = CreateObject("ADODB.Command")
objComm.ActiveConnection = objConn
objComm.Properties("Page Size") = 1000
objComm.CommandText = strBase & strFilter & strAttrs & strScope
set objRS = objComm.Execute
objRS.MoveFirst
while Not objRS.EOF
Wscript.Echo objRS.Fields(0).Value
objRS.MoveNext
wend
"LittlePython" <Li**********@lost.com> wrote in message
news:g_7Jf.33401$0H1.22606@trnddc04... I am have trouble finding a simple working example of using ADO to search Active Directory. I am hoping someone could point me to a generic working script that connects to AD and pulls up a recordset to help me get started into the right direction in learning ADO, ADSI on Python.
I notice there is no adodb.command. This is not required?
Thx for the example!
"Roger Upole" <ru****@hotmail.com> wrote in message
news:11*************@sp6iad.superfeed.net... Here's a short example that uses ADO to search for a user by wildcard.
import win32com.client c = win32com.client.Dispatch("ADODB.Connection") c.Open("Provider=ADSDSOObject")
rs,rc=c.Execute(""" SELECT adspath, title, name From 'LDAP://DC=yourdomain, DC=COM' where objectClass='user' and name='Roger*' """)
while not rs.EOF: for f in rs.Fields: print f.Name, f.Value rs.MoveNext()
hth Roger
"LittlePython" <Li**********@lost.com> wrote in message news:56aJf.78250$_D1.4370@trnddc03... Thanks but I was looking more for ADO com object than ADSI or ldap. For some strange reason it is very hard to locate any working scripts
that use ADO to connect and search AD. Is there an issue with ADO and python when connecting to AD? I have try to build one myself with no luck. I think my problem is with adodb.command calls.
Thanks for your response.
"alex23" <wu*****@gmail.com> wrote in message news:11*********************@f14g2000cwb.googlegro ups.com... Heya,
There are a couple of examples on the O'Reilly site. These two are taken from 'Active Directory Cookbook', the first uses a COM object while the second uses a native LDAP module:
http://www.rallenhome.com/books/adco...thon_com.py.tx t
http://www.rallenhome.com/books/adco...thon_ldap.py.t xt This might give you a start.
- alex23
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption
=----
You could also accomplish the same thing using the
Command object, but this way is usually more concise
for plain Sql.
Roger
"LittlePython" <Li**********@lost.com> wrote in message
news:UtaJf.78260$_D1.52493@trnddc03... I notice there is no adodb.command. This is not required? Thx for the example! "Roger Upole" <ru****@hotmail.com> wrote in message news:11*************@sp6iad.superfeed.net... Here's a short example that uses ADO to search for a user by wildcard.
import win32com.client c = win32com.client.Dispatch("ADODB.Connection") c.Open("Provider=ADSDSOObject")
rs,rc=c.Execute(""" SELECT adspath, title, name From 'LDAP://DC=yourdomain, DC=COM' where objectClass='user' and name='Roger*' """)
while not rs.EOF: for f in rs.Fields: print f.Name, f.Value rs.MoveNext()
hth Roger
"LittlePython" <Li**********@lost.com> wrote in message news:56aJf.78250$_D1.4370@trnddc03... Thanks but I was looking more for ADO com object than ADSI or ldap. For some strange reason it is very hard to locate any working scripts that use ADO to connect and search AD. Is there an issue with ADO and
python when connecting to AD? I have try to build one myself with no luck. I think my problem is
with adodb.command calls.
Thanks for your response.
"alex23" <wu*****@gmail.com> wrote in message news:11*********************@f14g2000cwb.googlegro ups.com... > Heya, > > There are a couple of examples on the O'Reilly site. These two are > taken from 'Active Directory Cookbook', the first uses a COM object > while the second uses a native LDAP module: > > http://www.rallenhome.com/books/adco...thon_com.py.tx t >
http://www.rallenhome.com/books/adco...thon_ldap.py.t xt > > This might give you a start. > > - alex23 >
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Do you know what this may mean?
C:\Documents and Settings\Administrator\Desktop\pytest>ADOSeach.py
Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\Desktop\pytest\ADOSeach.py" ,
lin
e 6, in ?
rs,rc=c.Execute("""
File "<COMObject ADODB.Connection>", line 3, in Execute
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 258,
in
_ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType,
argTypes
) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Provider',
'Tabl
e does not exist.', None, 1240640, -2147217865), None)
C:\Documents and Settings\Administrator\Desktop\pytest>
"Roger Upole" <ru****@hotmail.com> wrote in message
news:11*************@sp6iad.superfeed.net... You could also accomplish the same thing using the Command object, but this way is usually more concise for plain Sql.
Roger
"LittlePython" <Li**********@lost.com> wrote in message news:UtaJf.78260$_D1.52493@trnddc03... I notice there is no adodb.command. This is not required? Thx for the example! "Roger Upole" <ru****@hotmail.com> wrote in message news:11*************@sp6iad.superfeed.net... Here's a short example that uses ADO to search for a user by wildcard.
import win32com.client c = win32com.client.Dispatch("ADODB.Connection") c.Open("Provider=ADSDSOObject")
rs,rc=c.Execute(""" SELECT adspath, title, name From 'LDAP://DC=yourdomain, DC=COM' where objectClass='user' and name='Roger*' """)
while not rs.EOF: for f in rs.Fields: print f.Name, f.Value rs.MoveNext()
hth Roger
"LittlePython" <Li**********@lost.com> wrote in message news:56aJf.78250$_D1.4370@trnddc03... > Thanks but I was looking more for ADO com object than ADSI or ldap. > For some strange reason it is very hard to locate any working
scripts that > use ADO to connect and search AD. Is there an issue with ADO and python > when connecting to AD? > I have try to build one myself with no luck. I think my problem is with > adodb.command calls. > > Thanks for your response. > > "alex23" <wu*****@gmail.com> wrote in message > news:11*********************@f14g2000cwb.googlegro ups.com... > > Heya, > > > > There are a couple of examples on the O'Reilly site. These two are > > taken from 'Active Directory Cookbook', the first uses a COM
object > > while the second uses a native LDAP module: > > > > >
http://www.rallenhome.com/books/adco...thon_com.py.tx > t > > > http://www.rallenhome.com/books/adco...thon_ldap.py.t > xt > > > > This might give you a start. > > > > - alex23 > > > > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World!
120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption
=----
It usually means the domain you specified can't be found.
Roger
"LittlePython" <Li**********@lost.com> wrote in message
news:w_aJf.18163$7C3.755@trnddc08... Do you know what this may mean?
C:\Documents and Settings\Administrator\Desktop\pytest>ADOSeach.py Traceback (most recent call last): File "C:\Documents and
Settings\Administrator\Desktop\pytest\ADOSeach.py" , lin e 6, in ? rs,rc=c.Execute(""" File "<COMObject ADODB.Connection>", line 3, in Execute File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
258, in _ApplyTypes_ result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes ) + args) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Provider', 'Tabl e does not exist.', None, 1240640, -2147217865), None)
C:\Documents and Settings\Administrator\Desktop\pytest> "Roger Upole" <ru****@hotmail.com> wrote in message news:11*************@sp6iad.superfeed.net... You could also accomplish the same thing using the Command object, but this way is usually more concise for plain Sql.
Roger
"LittlePython" <Li**********@lost.com> wrote in message news:UtaJf.78260$_D1.52493@trnddc03... I notice there is no adodb.command. This is not required? Thx for the example! "Roger Upole" <ru****@hotmail.com> wrote in message news:11*************@sp6iad.superfeed.net... > Here's a short example that uses ADO to search for a > user by wildcard. > > import win32com.client > c = win32com.client.Dispatch("ADODB.Connection") > c.Open("Provider=ADSDSOObject") > > rs,rc=c.Execute(""" > SELECT adspath, title, name > From 'LDAP://DC=yourdomain, DC=COM' > where objectClass='user' and name='Roger*' > """) > > while not rs.EOF: > for f in rs.Fields: > print f.Name, f.Value > rs.MoveNext() > > hth > Roger > > "LittlePython" <Li**********@lost.com> wrote in message > news:56aJf.78250$_D1.4370@trnddc03... > > Thanks but I was looking more for ADO com object than ADSI or
ldap. > > For some strange reason it is very hard to locate any working scripts that > > use ADO to connect and search AD. Is there an issue with ADO and python > > when connecting to AD? > > I have try to build one myself with no luck. I think my problem is with > > adodb.command calls. > > > > Thanks for your response. > > > > "alex23" <wu*****@gmail.com> wrote in message > > news:11*********************@f14g2000cwb.googlegro ups.com... > > > Heya, > > > > > > There are a couple of examples on the O'Reilly site. These two
are > > > taken from 'Active Directory Cookbook', the first uses a COM object > > > while the second uses a native LDAP module: > > > > > > > > > http://www.rallenhome.com/books/adco...thon_com.py.tx > > t > > > > > >
http://www.rallenhome.com/books/adco...thon_ldap.py.t > > xt > > > > > > This might give you a start. > > > > > > - alex23 > > > > > > > > > > > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure
Usenet News==---- > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups > ----= East and West-Coast Server Farms - Total Privacy via
Encryption =----
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Never mind , I know what's wrong ... need to use the right account. It works
great and is a great example .. thx
"LittlePython" <Li**********@lost.com> wrote in message
news:w_aJf.18163$7C3.755@trnddc08... Do you know what this may mean?
C:\Documents and Settings\Administrator\Desktop\pytest>ADOSeach.py Traceback (most recent call last): File "C:\Documents and
Settings\Administrator\Desktop\pytest\ADOSeach.py" , lin e 6, in ? rs,rc=c.Execute(""" File "<COMObject ADODB.Connection>", line 3, in Execute File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
258, in _ApplyTypes_ result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes ) + args) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Provider', 'Tabl e does not exist.', None, 1240640, -2147217865), None)
C:\Documents and Settings\Administrator\Desktop\pytest> "Roger Upole" <ru****@hotmail.com> wrote in message news:11*************@sp6iad.superfeed.net... You could also accomplish the same thing using the Command object, but this way is usually more concise for plain Sql.
Roger
"LittlePython" <Li**********@lost.com> wrote in message news:UtaJf.78260$_D1.52493@trnddc03... I notice there is no adodb.command. This is not required? Thx for the example! "Roger Upole" <ru****@hotmail.com> wrote in message news:11*************@sp6iad.superfeed.net... > Here's a short example that uses ADO to search for a > user by wildcard. > > import win32com.client > c = win32com.client.Dispatch("ADODB.Connection") > c.Open("Provider=ADSDSOObject") > > rs,rc=c.Execute(""" > SELECT adspath, title, name > From 'LDAP://DC=yourdomain, DC=COM' > where objectClass='user' and name='Roger*' > """) > > while not rs.EOF: > for f in rs.Fields: > print f.Name, f.Value > rs.MoveNext() > > hth > Roger > > "LittlePython" <Li**********@lost.com> wrote in message > news:56aJf.78250$_D1.4370@trnddc03... > > Thanks but I was looking more for ADO com object than ADSI or
ldap. > > For some strange reason it is very hard to locate any working scripts that > > use ADO to connect and search AD. Is there an issue with ADO and python > > when connecting to AD? > > I have try to build one myself with no luck. I think my problem is with > > adodb.command calls. > > > > Thanks for your response. > > > > "alex23" <wu*****@gmail.com> wrote in message > > news:11*********************@f14g2000cwb.googlegro ups.com... > > > Heya, > > > > > > There are a couple of examples on the O'Reilly site. These two
are > > > taken from 'Active Directory Cookbook', the first uses a COM object > > > while the second uses a native LDAP module: > > > > > > > > > http://www.rallenhome.com/books/adco...thon_com.py.tx > > t > > > > > >
http://www.rallenhome.com/books/adco...thon_ldap.py.t > > xt > > > > > > This might give you a start. > > > > > > - alex23 > > > > > > > > > > > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure
Usenet News==---- > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups > ----= East and West-Coast Server Farms - Total Privacy via
Encryption =----
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
With help I have been able to put together a little example. It illustrates
several different ways..
import win32com.client
c = win32com.client.Dispatch("ADODB.Connection")
c.Open("Provider=ADSDSOObject")
##Check if connected to AD
if bool(c.state): print "Connected to AD"
## This uses sql dialect with no command object
##rs,rc=c.Execute("""
##SELECT adspath, title, name
##From 'LDAP://DC=AD,DC=LOCAL'
##where objectCategory='Person' and objectClass='user' and name='*'
##""")
##This uses ADSI dialect with not command object
##rs,rc=c.Execute("""
##<LDAP://DC=AD,DC=LOCAL>;\
##(&(objectCategory=Person)(objectClass=user)(name =*));\
##name,adspath,title;\
##subtree
##""")
##Command com with properties in sql dialect
##comm = win32com.client.Dispatch("ADODB.Command")
##comm.ActiveConnection = c
##comm.Properties('Page size').value=1000
##comm.CommandText = ("""\
##SELECT adspath, title, name \
##From 'LDAP://DC=AD,DC=LOCAL' \
##where objectCategory='Person' and objectClass='user' and name='*'\
##""")
##rs,rc=comm.Execute()
##Command com with properties in ADSI dialect
##ADS_SCOPE_SUBTREE = 2
##ADS_SCOPE_ONELEVEL = 1
##ADS_SCOPE_BASE = 0
##comm = win32com.client.Dispatch("ADODB.Command")
##comm.ActiveConnection = c
##comm.Properties('Page size').value=1000
##comm.Properties('searchscope').value=ADS_SCOPE_S UBTREE
##comm.CommandText = ("""<LDAP://DC=AD,DC=LOCAL>;\
##(&(objectCategory=Person)(objectClass=user)(name =*));\
##name,adspath,title;""")
##rs,rc=comm.Execute()
##Connect using recordset object in ADSI Dialect
##rs = win32com.client.Dispatch("ADODB.recordset")
##rs.ActiveConnection = c
##rs.source = ("""<LDAP://DC=AD,DC=LOCAL>;\
##(&(objectCategory=Person)(objectClass=user)(name =*));\
##name,adspath,title;\
##subtree""")
##rs.Open()
##Connect using recordset object in sql Dialect
##rs = win32com.client.Dispatch("ADODB.recordset")
##rs.ActiveConnection = c
##rs.source = ("""\
##SELECT adspath, title, name \
##From 'LDAP://DC=AD,DC=LOCAL' \
##where objectCategory='Person' and objectClass='user' and name='*'\
##""")
##rs.Open()
##while not rs.EOF:
## for f in rs.Fields:
## print f.Name, f.Value
## rs.MoveNext()
c.close
c = None This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jay Chan |
last post by:
We have just installed a SQL Server 2000 (SP 3A) onto a computer that
has Windows-2003 Server on it. Now, we cannot get access to that
database server from other computers. Seem like this may be an...
|
by: microsoft |
last post by:
Hi People, when I try to modify an active directory user programatically, I
receive the following exception:
The server is unwilling to process the request
Reading the microsoft web site, I...
|
by: Mario Rodriguez |
last post by:
Hi people. I have a problem adding users to Win2003 active directory
programatically. When I execute my app throws the following exception:
.................The specified directory service...
|
by: Andrew |
last post by:
Hey all,
Working on revamping our Intranet here and making use of the LDPA, Active
Directory, Directory Services, etc. that .Net provides. I am still fairly
new on this subject, so the problem...
|
by: Leo_Surf |
last post by:
Hello,
I need your help adding user in Active Directory from ASP.net website. Could
any one provide me the complete code for the html page. As this is my
curriculam project and I dont have any...
|
by: tangus via DotNetMonster.com |
last post by:
Hello all, I'm really struggling with getting some Active Directory code to
work in ASP.NET. Can you please provide assistance? I am executing the
following code:
Dim enTry As DirectoryEntry =...
|
by: Hriday |
last post by:
Hi there, Please help me..It is urgent
This is Hriday, working on windows authentication with
Active Directory...
My requirment is when a user sends a request to my web
Applicatoin I want to...
|
by: RTT |
last post by:
here is my current situation. I develop a program on my computer's
localhost. From there i contact Active directory succesfull using a
connectionstring like:...
|
by: Jim in Arizona |
last post by:
My goal, somehow, is to populate a dropdownlist with all the user names
in active directory. I don't even know where to begin, really.
I added a reference to System.DirectoryServices so I could...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |