1. 程式人生 > 其它 >使用OpenLDAP 操作 Windows Active Directory

使用OpenLDAP 操作 Windows Active Directory

《節選自 Netkiller LDAP 手札》

第 4 章 Active Directory

通過ldapsearch查詢Windows Active Directory 是一件很有趣事情。

列出所有員工姓名

ldapsearch -x -H ldap://192.168.19.238 -D [email protected] -w 12345678 -b 'OU=china,DC=company,DC=com' '(&(objectCategory=person)(objectClass=user)(company=*)(mail=*))'|grep '^name::' | awk -F ' ' '{print $2}' |base64 --decode | sed 's/)/)rn/g'		

統計員工數目

ldapsearch -x -H ldap://192.168.19.238 -D [email protected] -w 12345678 -b 'OU=china,DC=company,DC=com' '(&(objectCategory=person)(objectClass=user)(company=*)(mail=*))'|grep '^name::' | wc -l		

製作通訊錄,或匯出郵件列表

ldapsearch -x -H ldap://192.168.19.238 -D [email protected] -w 12345678 -b 'OU=china,DC=company,DC=com' '(&(objectCategory=person)(objectClass=user)(company=*)(mail=*))'|grep ^mail:|awk -F ' ' '{print $2}'		

列出 name mail mobile telephoneNumber

ldapsearch -x -H ldap://192.168.19.238 -D [email protected] -w 12345678 -b 'OU=china,DC=company,DC=com' '(&(objectCategory=person)(objectClass=user)(name=*)(mail=*))' name mail mobile telephoneNumber