我正在尝试在所有AD和域中运行python查询find_user。 但是此脚本仅适用于EU域,因为该脚本当前正在EU服务器上运行。有人可以帮助我如何重新构造查询以同时检查其他域用户吗?
我正在使用活动目录库来提取脚本中的用户详细信息。
def find_user(user_id):
logger.debug('Begin find_user with %s' % user_id)
pythoncom.CoInitialize()
try:
user = active_directory.find_user(user_id)
if user is not None:
muid = user.employeeID
username = user.displayName
user_dict = {'uid': user_id, 'muid': muid, 'displayName': username, 'member_of': user.memberOf}
logger.debug('display username %s ' % user_dict)
member_of = user.memberOf
logger.debug('member_of: %s' % member_of)
for gr in member_of:
logger.warn('%s is in Group: %s' % (muid, gr))
#print('%s is in Group: %s' % (muid, gr))
return user_dict
else:
logger.error('No AD information for %s' % user_id)
raise NoADInformationError('No AD information for %s' % user_id)
except Exception as e:
logger.error('Active Directory User not fetched %s' % user_id)
active_directory._CACHE = {}
active_directory._connection = None
raise NoADInformationError('No AD information for %s ;Exception %s' % (user_id, e))