By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

Win32Com LDAP Enumerate Users

P: 1
I am attempting to scan a Windows Active Directory using wincom32.client and LDAP to pull a list of users and their attributes.

My problem is that I am unable to get the search working:
Expand|Select|Wrap|Line Numbers
  1. import win32com.client, win32net
  2. strFQADDomainName = win32com.client.GetObject('LDAP://rootDSE').Get("defaultNamingContext")
  3. arrDomainObjects = win32com.client.GetObject("LDAP://" + strFQADDomainName + ">;(&(&(&(objectCategory=user)(name=*))))")
  4.  
When I run that I receive the following error:
arrDomainObjects = win32com.client.GetObject("LDAP://" + strFQADDomainName +
">;(&(&(&(objectCategory=user)(name=*))))")
File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 72, in
GetObject
return Moniker(Pathname, clsctx)
File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 87, in
Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
pywintypes.com_error: (-2147463168, 'OLE error 0x80005000', None, None)
If I just use:
Expand|Select|Wrap|Line Numbers
  1. arrDomainObjects = win32com.client.GetObject("LDAP://" + strDomainName)
  2.  
Then it lists out the root level OU's. But it will not go any farther than the root level OU's.
If I hard code the OU path then it will pull the users
Expand|Select|Wrap|Line Numbers
  1. arrDomainObjects = win32com.client.GetObject("LDAP://cn=batman,ou=users" + strFQADDomainName)
  2.  
My goal is to pull a list of users like this would
Expand|Select|Wrap|Line Numbers
  1. strFQADDomainName = win32com.client.GetObject('LDAP://rootDSE').Get("defaultNamingContext")
  2. strDomainName = '.'.join(strFQADDomainName.split('DC=')).replace(',', '')[1:]
  3. arrDomainObjects = win32com.client.GetObject("WinNT://" + strDomainName)
  4. arrDomainObjects.Filter = ["User"]
  5.  
If the win32com.client with LDAP does not support a search (with after spending several hours googling, and searching I suspect it doesn't) then is there a way for me to pull fully qualified DN from the WinNT version so that I can run a loop based on the info that I pull from WinNT
For example:
Expand|Select|Wrap|Line Numbers
  1. strFQADDomainName = win32com.client.GetObject('LDAP://rootDSE').Get("defaultNamingContext")
  2. strDomainName = '.'.join(strFQADDomainName.split('DC=')).replace(',', '')[1:]
  3. arrDomainObjects = win32com.client.GetObject("WinNT://" + strDomainName)
  4. arrDomainObjects.Filter = ["User"]
  5. for lpDomainObjects in arrDomainObjects:
  6.   print lpDomainObjects.dn
  7.  
I would prefer to strictly use LDAP for this, but I have a feeling that I will need to use WinNT for part of it too.

Any suggestions?
Dec 16 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.