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