Monday, October 05, 2009

Perl script to create AD User from Unix Server

#!/usr/bin/perl

use Net::LDAP;

$Ad = Net::LDAP->new("sogolab.com", version => 3, port => 389) or die("failed $!");
print "Failed connecting" if(!$Ad);

## bind as an admin or someone who has privileges to create an user
$b = $Ad->bind(dn => 'CN=Administrator,CN=Users,DC=sogolab,DC=com', password => 'XSSSXXX') or die("failed $!; ".$b->error);

$result = $Ad->add( 'cn=Ratish Kumar,cn=Users,DC=sogolab,DC=com',
attr => [
'cn' => 'Ratish Kumar',
'sn' => 'Ratish',
'mail' => 'ratish@kmail.com',
'sAMAccountName' => 'ratish',
'userAccountControl' => '544',
'objectclass' => ['top', 'person','organizationalPerson','user' ]]
);

$result->code && warn "failed to add entry: ", $result->error ;

No comments: