Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...What you have done for people like me is immeasurably helpful."

Geography

Where in the world do Tek-Tips members come from?

changing "CN" fields via perl script

Coworker (IS/IT--Management)
30 Jun 12 12:03
Hello,
the task is to change common names in active directory via perl script. The problem is that I can retrieve data with my script but can't change CN. During execution I have not any errors. Here is my code:
$ldap->modify($dn, replace => { "cn" => $data_concat } );
if ($?==0){
print " $cn successfully changed to => $data_concat \n";
}
if ($?>0){
print "there were problems during changes of $cn, please check ... ";
}

Give advice!
PinkeyNBrain (IS/IT--Management)
24 Jul 12 18:58
Have you checked out: http://www.perlmonks.org/?node_id=32196
Two things it discusses regarding Net:LDAP
- Using the 'code' method to look for errors
- Specifically in this case:[code]sub changename {
my $entry = shift;
my $newname = shift;
$entry->replace(cn => $newname);
}[/code]

Obviously lots of details left out in this posting. Would be best to review the web link.
PinkeyNBrain (IS/IT--Management)
24 Jul 12 19:03
The code in that previous post should have shown up like this (not sure why it didn't)

CODE

sub changename { 
my $entry = shift; 
my $newname = shift; 
$entry->replace(cn => $newname); 
} 
Coworker (IS/IT--Management)
25 Jul 12 5:32
to PinkeyNBrain: thaks for reply!
I solved this 2 weeks ago.
Information for those who has the same task:
method "modify" which I first tried to use is just for CN attributes (for ex. phone, street and so on) and you can't rename CN with it.
To rename CN Perl offers "moddn" method which I successfully used to solve my task:

$rc = $ldap->moddn($dn, newrdn => "cn=$data_concat", deleteoldrdn => 1);
if ($rc->code) {
print "Error renaming user: ", $rc->error, "\n";
}
else {
print "Succesfully renamed user \n";
}

But be careful always when you try LDAP scripts on productive systems! Try them always first on testing systems if possible.
I also tried to solve my task via "replace" method but for some reason it didn't work.
PinkeyNBrain (IS/IT--Management)
25 Jul 12 12:10
In return thanks for sharing the resolution you found. Truth be told, I had question for another Tek-Tip forum. I like this site and when I post out here I feel obligated to try and answer someone else's questions (I look for those that have zero replies). I've been programing with Perl since roughly 1991 and subsequently gravitate toward this forum to look for unanswered posts.... Perl is hands down my favorite language.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close