Conor I believe MS AD requires a secure connection. your connection is missing ldaps as shown below
my $ad = Net::LDAP->new("ldaps://$PDC") || die "Could not connect!"; Below is from one of my AD scripts that works my $obj_ldap = Net::LDAP->new("ldaps://$ldap_server") or die "$@"; my $mesg = $obj_ldap->bind( $ADUserDN, password => $ADUser_Password ); my $mesg->code && die "ERROR:AD Connection Failure [". $mesg->error."]"; Try that Tony B. Okusanya From: "Conor Lillis" <conorlil...@angloirishbank.ie> To: <perl-win32-users@listserv.ActiveState.com> Date: 09/22/2011 06:03 AM Subject: AD / ldap update Sent by: perl-win32-users-boun...@listserv.activestate.com Hi all, I have a requirement to add a new primary SMTP address to our users, and retain the existing primary SMTP address as an alias. The attribute in AD that holds these values is ?proxyAddresses?. Exchange uses any SMTP values in lowercase (eg smtp:co...@angloirishbank.ie) as aliases, and will stamp outgoing SMTP email with the value that starts with SMTP: uppercase (eg SMTP:conorlil...@angloirishbank.ie). I have attached below the script I am trying to use for proof of concept, and while I am able to retrieve the current attribute values, I am unable to successfully write the new values to AD. I should clarify that I am basing the script on previous working scripts and various articles on the web, and am not a full time coder so layout / coding is not necessarily optimum ;-) Any assistance greatly appreciated. I am testing in disabled accounts in the OU below so as not to impact on live accounts? system("cls"); use Net::LDAP; my $PDC = "PDC.domain.lan"; my $userid = "UserID\@domain.lan"; my $password = "Password"; my $newdomain = "NewDomain.com"; my $base = "ou=Disabled Accounts,ou=IOM,ou=angloirishbank,DC=anglo,DC=lan"; my $ad = Net::LDAP->new("$PDC") || die "Could not connect!"; $ad->bind(dn =>"$userid", password=>"$password") || die $^E; my @args = ( base => $base, filter => "(mail=*)", attrs => "proxyAddresses", ); my $results = $ad->search(@args); my $count = $results->count; print "Count = $count\n"; my $entry; my $counter; for (my $i=0; $i<$count; $i++) { $entry = $results->entry($i); # Get First Name and Surname for new SMTP address to be firstname.surn...@domain.com my $FirstName = ($entry->get_value('givenName')); my $SurName = ($entry->get_value('sn')); @proxyAddresses =$entry->get_value('proxyAddresses'); my $arraycount = 0; # Set all existing SMTP addresses to lowercase, Use $arraycount variable to update record within array foreach my $Proxy(@proxyAddresses) { if (grep /SMTP:/, $Proxy) { $Proxy=lc($Proxy); $proxyAddresses[$arraycount]=$Proxy; } ++$arraycount; print "$name\tOLD\t:\t$Proxy\n"; } if (!grep /SMTP:$FirstName.$SurName\@$newdomain/i, @proxyAddresses) { push(@proxyAddresses,"SMTP:$FirstName.$SurName\@$newdomain"); } # Print the new array to ensure appropriate values have been added / changed foreach my $Proxy(@proxyAddresses){print "$name\tNEW\t:\t$Proxy\n";} # Update AD (hopefully) $entry->replace('proxyAddresses',@proxyAddresses); $entry->update($ad)|| die print "There was an error updating record for $name\nError Text\t:\t".$^E; # Retrieve the updated values to validate print "\nRetrieving NEW SMTP Values\n\n\n"; my @proxyAddresses =$entry->get_value('proxyAddresses'); foreach my $Proxy(@proxyAddresses){print "$name\tADSI\t:\t$Proxy\n";} } ********************************************************************** Private, Confidential and Privileged. This e-mail and any files and attachments transmitted with it are confidential and/or privileged. They are intended solely for the use of the intended recipient. The content of this e-mail and any file or attachment transmitted with it may have been changed or altered without the consent of the author. If you are not the intended recipient, please note that any review, dissemination, disclosure, alteration, printing, circulation or transmission of this e-mail and/or any file or attachment transmitted with it, is prohibited and may be unlawful. This e-mail and any files and attachments transmitted with it are unencrypted unless specifically advised otherwise. If you have received this e-mail or any file or attachment transmitted with it in error please notify Anglo Irish Bank Corporation Limited, Stephen Court, 18/21 St Stephen's Green, Dublin 2, Ireland, telephone no: +353-1-6162000. Directors: A.M. Dukes Chairman, A.M.R. Aynsley (Australian) Chief Executive, N. Cawley, A. Eames, M.A. Keane, P.G. Kennedy Registered Office: Stephen Court, 18/21 St Stephen's Green, Dublin 2 Ireland Registered in Ireland: No 22045 Anglo Irish Bank Corporation Limited is regulated by the Central Bank of Ireland. Anglo Irish Bank Corporation Limited (trading as Anglo Irish Bank Private Banking) is regulated by the Central Bank of Ireland. Anglo Irish Assurance Company Limited is regulated by the Central Bank of Ireland. ********************************************************************** _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs U.S. BANCORP made the following annotations --------------------------------------------------------------------- Electronic Privacy Notice. This e-mail, and any attachments, contains information that is, or may be, covered by electronic communications privacy laws, and is also confidential and proprietary in nature. If you are not the intended recipient, please be advised that you are legally prohibited from retaining, using, copying, distributing, or otherwise disclosing this information in any manner. Instead, please reply to the sender that you have received this communication in error, and then immediately delete it. Thank you in advance for your cooperation. ---------------------------------------------------------------------
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs