# Searching Active Directory

**URL:** https://rubytalk.org/t/searching-active-directory/26157
**Category:** ruby-talk
**Created:** [27 March 2006 16:36 UTC](https://rubytalk.org/t/searching-active-directory/26157 "2006-03-27T16:36:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Robert\_Boone](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@Robert\_Boone](https://rubytalk.org/u/Robert_Boone)
#### Post date: [27 March 2006 16:36 UTC](https://rubytalk.org/t/searching-active-directory/26157/1 "2006-03-27T16:36:51Z")

</div>

Hello,  
&nbsp;&nbsp;&nbsp;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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

### Author: ![Dave\_Burt2](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/dave_burt2/32/2036_2.png) [@Dave\_Burt2](https://rubytalk.org/u/Dave_Burt2)
#### Post date: [28 March 2006 07:58 UTC](https://rubytalk.org/t/searching-active-directory/26157/2 "2006-03-28T07:58:55Z")

</div>

Robert Boone wrote:

> &nbsp;&nbsp;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
