I had this working before. Now, after flatting and rebuilding machine, I can't seem to get pyad working.
My script uses adquery to get the members of a domain.
I've installed pyad and pywin32 with the correct versions. I am using Python 3.6.
I keep getting the following error:
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Active Directory', 'The specified domain either does not exist or could not be contacted.\r\n', None, 0, -2147217865), None)
The script ran before perfectly so I am assuming it is an installation issue.
Here is the function I wrote:
from pyad import adquery, aduser, adbase
def call_adquery(domain, debug):
global numRow
log.info('Domain: {}'.format(domain))
df = pd.DataFrame()
z_obj = adquery.ADQuery()
t = datetime.today().strftime('%m/%d/%Y')
i = 0
if domain == 'satyan':
wc = "mailNickname='satyan'"
domain = 'redmond'
else:
wc = """
objectClass='user'
and showInAddressBook='*'
and manager='*'
and not mailNickname='b-*'
"""
dn = base_dn = 'OU=UserAccounts,DC={0}, DC=corp,DC=microsoft,DC=com'.format(domain)
att = ['name', 'displayName', 'title', 'company', 'msExchHideFromAddressLists',
'manager', 'mail', 'mailNickname', 'distinguishedName', 'extensionAttribute4',
'extensionAttribute2','sn','cn','givenName', 'instanceType','userPrincipalName',
'objectCategory']
z_obj.execute_query(attributes=att, where_clause=wc, base_dn=dn, type='GC')
for row in z_obj.get_results():
i += 1
numRow += 1
n = pd.Series.from_array(row)
log.info("{0}, {1}, {2}, {3}".format(numRow, i, domain, row['name']))
n['domain'] = domain
n['date'] = t
df = df.append(n, ignore_index=True)
if (debug==True) and (i == 10): break
log.info('Count for {0}: {1}'.format(domain, i))
return df