Created
September 18, 2012 13:09
-
-
Save kwoods/3743005 to your computer and use it in GitHub Desktop.
Search for Computer Names using List of Users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will take a list of user names | |
# formatted like so: Amos, Deborah K | |
# and convert the name into LastnameFirstInitial | |
# to use for searching Active Directory for | |
# matching computer names... | |
require 'net-ldap' | |
@ldap = Net::LDAP.new :host => "ip-addr-of-dc", | |
:port => 389, :base=> "dc=my,dc=domain,dc=com", | |
:auth => { | |
:method => :simple, | |
:username => "[email protected]", | |
:password => "" | |
} | |
def ad_search(full_name) | |
search_filter = full_name.split(",")[0] + full_name.split(",")[1].lstrip.chr | |
filter = Net::LDAP::Filter.eq("cn", search_filter + "*") | |
treebase = "dc=my, dc=domain, dc=com" | |
full_name = full_name.sub(/,/, " ").chomp | |
@ldap.search(:base => treebase, :filter => filter) do |entry| | |
puts "#{full_name}, #{search_filter}, #{entry.dn}" | |
end | |
end | |
users = IO.readlines("c:/exclusion_list.txt") | |
users.each do |full_name| | |
ad_search(full_name) | |
end | |
p ldap.get_operation_result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment