# Searching Active Directory

**URL:** <https://www.ruby-forum.com/t/searching-active-directory/87799>\
**Category:** Ruby\
**Created:** [March 27, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/searching-active-directory/87799 "2006-03-27T18:36:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Boone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47774/32.png) [@Robert\_Boone](https://www.ruby-forum.com/u/Robert_Boone)\
**Post date:** [March 27, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/searching-active-directory/87799/1 "2006-03-27T18:36:34Z")

</div>

Hello,  
I have been trying to research this myself but I haven’t come up with  
much. I’m mostly a linux guy so I don’t know much about the inner  
workings of AD. This is what I’m trying to do, I need to search through  
each OU for users then find the value of one of those users attributes.  
I’ve looked at the docs for WIN32OLE and I just don’t see how to use it.  
I’ve googled and I’ve seen some perl examples but the method getObject  
in the ruby docs. I would use perl but those docs aren’t complete  
either. I could really use some help on this.

Thanks,

Robert Boone

---

<div class="post-metadata">

**Author:** ![Robert\_Boone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47774/32.png) [@Robert\_Boone](https://www.ruby-forum.com/u/Robert_Boone)\
**Post date:** [March 28, 2006, 9:59am UTC](https://www.ruby-forum.com/t/searching-active-directory/87799/2 "2006-03-28T09:59:36Z")

</div>

Robert Boone wrote:

> I have been trying to research this myself but I haven’t come up with  
> much. I’m mostly a linux guy so I don’t know much about the inner  
> workings of AD. This is what I’m trying to do, I need to search through  
> each OU for users then find the value of one of those users attributes.  
> I’ve looked at the docs for WIN32OLE and I just don’t see how to use it.  
> I’ve googled and I’ve seen some perl examples but the method getObject  
> in the ruby docs. I would use perl but those docs aren’t complete  
> either. I could really use some help on this.

Hi Robert,

This VBScript:

Set x = CreateObject(“Foo.Bar”)  
Set y = GetObject(“Foo.Bar”)

Translates to this Ruby code:

require ‘win32ole’  
x = WIN32OLE.new(“Foo.Bar”)  
y = WIN32OLE.connect(“Foo.Bar”)

Now, Active Directory…

# connect to ADSI

domain = WIN32OLE.connect(“WinNT://domain\_name\_goes\_here”)  
users = []

# collect User instances out of objects in the domain

domain.each {|obj| users \<\< obj if obj.Class == “User” }

# print the FullName attribute of all users whose Name (which should be

unique)

# is “dburt”

puts users.select {|u| u.Name == “dburt” }.map! {|u| u.FullName }

I hope that helps.

Cheers,  
Dave
