Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing "CN" fields via perl script

Status
Not open for further replies.

Coworker

IS-IT--Management
Aug 16, 2010
3
UA
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!
 
Have you checked out: 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.
 
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); 
}
 
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top