# Creating new users with LDAP

**URL:** <https://rubytalk.org/t/creating-new-users-with-ldap/66697>\
**Category:** ruby-talk\
**Created:** [14 November 2012 18:19 UTC](https://rubytalk.org/t/creating-new-users-with-ldap/66697 "2012-11-14T18:19:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [14 November 2012 18:19 UTC](https://rubytalk.org/t/creating-new-users-with-ldap/66697/1 "2012-11-14T18:19:25Z")

</div>

Hi,  
Trying to create a new user in AD with Ruby: Net: Ldap. I am getting  
error:

$ ruby newUser.rb  
authentication succeeded  
#\<OpenStruct code=1, message="Operations Error"\>

This is the code:

require 'rubygems'  
require 'net/ldap'

ldap = Net::LDAP.new  
ldap.host = '192.1.1.0'  
ldap.port = 389  
ldap.auth 'myDomain\myUsername', 'pwd'  
if ldap.bind  
&nbsp;&nbsp;puts "authentication succeeded"  
else  
&nbsp;&nbsp;&nbsp;puts "authentication failed"  
&nbsp;&nbsp;p ldap.get\_operation\_result  
end  
dn ='cn=new user,ou=myOU,ou=myOU1,ou=myOU2,ou=myOU3,dc=blabla,dc=local'  
&nbsp;&nbsp;attr = {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:cn =\> "new user",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:objectclass =\> ["top", "inetorgperson"],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:sn =\> "nuser",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:mail =\> "nuser@anyhosp.com"  
&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;Net::LDAP.open(:host =\> "192.1.1.0") do |ldap|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ldap.add(:dn =\> dn, :attributes =\> attr)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p ldap.get\_operation\_result  
end

what am I doing wrong?  
Thanks in advance

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