# -*- coding: utf-8 -*-
import codecs, sys
"""
codepage = 'cp866'
outf = codecs.getwriter(codepage)(sys.stdout, errors='replace')
sys.stdout = outf
"""
import win32com.client
def get_all_users_in_domain():
conn = win32com.client.Dispatch("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open("Active Directory Provider")
query = "SELECT * FROM 'LDAP://DC=corp,DC=ru' WHERE objectClass='user' AND objectCategory='person'"
rs = conn.Execute(query)[0]
users = []
while not rs.EOF:
obj = win32com.client.GetObject(rs.Fields(0).Value)
users.append (obj)
rs.MoveNext()
conn.Close()
return(users)
def get_disabled_user_in_domain(users):
enabled_users = []
for x in range(len(users)):
if users[x].AccountDisabled:
enabled_users.append(users[x])
return (enabled_users)
def print_user(users):
print "Count user %d"%(len(users))
for x in range(0, len(users)):
print users[x].Name.replace(u'SN=','')
users = get_all_users_in_domain()
enabled_users = get_enabled_user_in_domain(users)
print_user(enabled_users)
print users[x].Name.replace(u'SN=','')
Кто нибудь подскажет?