Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

changing "CN" fields via perl script

changing "CN" fields via perl script

changing "CN" fields via perl script

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!

RE: changing "CN" fields via perl script

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);

Obviously lots of details left out in this posting. Would be best to review the web link.

RE: changing "CN" fields via perl script

The code in that previous post should have shown up like this (not sure why it didn't)


sub changename { 
my $entry = shift; 
my $newname = shift; 
$entry->replace(cn => $newname); 

RE: changing "CN" fields via perl script

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.

RE: changing "CN" fields via perl script

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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! Already a Member? Login

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