Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'net/ldap'
- def get_ldap_response(ldap)
- msg = "Response Code: #{ ldap.get_operation_result.code }, Message: #{ ldap.get_operation_result.message }"
- raise msg unless ldap.get_operation_result.code == 0
- end
- ldap = Net::LDAP.new :host => # your LDAP host name or IP goes here,
- :port => # your LDAP host port goes here,
- :encryption => :simple_tls,
- :base => # the base of your AD tree goes here,
- :auth => {
- :method => :simple,
- :username => # a user w/sufficient privileges to read from AD goes here,
- :password => # the user's password goes here
- }
- search_param = # the AD account goes here
- result_attrs = ["sAMAccountName", "displayName", "mail"] # Whatever you want to bring back in your result set goes here
- # Build filter
- search_filter = Net::LDAP::Filter.eq("sAMAccountName", search_param)
- # Execute search
- ldap.search(:filter => search_filter, :attributes => result_attrs) { |item|
- puts "#{item.sAMAccountName.first}: #{item.displayName.first} (#{item.mail.first})"
- }
- get_ldap_response(ldap)
Add Comment
Please, Sign In to add comment