Thanks all for your assistance.
I directly contacted Aaron Giuoco as a result of stumbling across his query 
here - http://www.nntp.perl.org/group/perl.ldap/2007/02/msg2489.html and he was 
good enough to provide me his working script.

Thanks all who contacted me directly or through the list.

I will take a further look at Win32::Exchange as I have a load more Exchange / 
AD related work coming down the pipe.

Regards,
Conor Lillis 

Senior Systems Administrator 
Group Infrastructure Services – Technical Services 
Group Operations 

Anglo Irish Bank Corporation Ltd
Tele:     +353 1 619 1819
Mobile: +353 86 815 1188
Fax: 

mailto:conorlil...@angloirishbank.ie
www.angloirishbank.ie
 Please consider the environment before printing this e-mail. 

-----Original Message-----
From: Steven Manross [mailto:ste...@manross.net] 
Sent: 24 September 2011 15:45
To: Conor Lillis; perl-win32-users@listserv.ActiveState.com
Subject: RE: AD / ldap update

So,
 
While you may or may not be using Microsoft Exchange, I wrote a Module
that does a lot of Active Directory calls that help you with tasks like
adding extra SMTP email addresses, etc (because it gets all this stuff
into the correct format.
 
Win32::Exchange does a lot of this for you.  It use Win32::OLE to do the
AD property sets.  It comes with sample scripts, and documentation on
how to use each function.
 
While Microsoft decided to only allow Powershell scripting to things
like Creating mailboxes in Exchange 2007 and 2010 (which invalidates
Perl access to a lot of the functionality of Exchange), Active Directory
property modifications should still work fine.  However, I don't have a
lab to work with against Exchange 2007 at the current time and can't
test against that current configuration.
 
The function in question that you really want to pay attention to is
SetAttributes..  If you are using Exchange 2007, the SetAttributes parts
will still work since you are really just setting AD properties for the
user account.
 
I use the CDO.Person interface for making manipulations like that.  Here
is a slightly modified excerpt from the example script that is provided
in my module.
 
If you use Exchange then My example script might work out of the box for
you.  Otherwise, you might need to edit it a little.  If you don't use
Exchange, you could take the _E2KSetAttributes or _E55SetAttributes
functions and modify it a little to suit your needs.  However, either
way, this module might give you some insights into how to form the
proxyaddresses (as an array) to the LDAP call you are currently trying
to make work. 
 
http://search.cpan.org/~smanross/Win32-Exchange_v0.046a/
 
if (!($provider = Win32::Exchange::Mailbox->new($info_store_server))) {
  print "$rtn - Error returning into main from new
($Win32::Exchange::VERSION)\n";
  exit 0;
}
if ($ver{ver} =~ /^6\../) {
  e60(); # E2K03 is the same as E2K.
}
 
sub e60 {
 
  if ($mailbox = $provider->GetMailbox($mailbox_alias_name)) {
    print "Got Mailbox successfully\n";
  } else {
    print "Mailbox did not exist\n";
    exit 0;
  }
  #be careful with proxy addresses..  You are deleting any addresses
that may exist already
  #if you set them via ProxyAddresses (you are now forewarned).
  push (@$proxies,'SMTP:'.$mailbox_alias_name.'@'.$email_domain);
  push (@$proxies,'SMTP:secondary@'.$email_domain);
  push (@$proxies,'SMTP:primary@'.$email_domain);
  push (@$proxies,'SMTP:tertiary@'.$email_domain);
 
  $Attributes{"IMailRecipient"}{ProxyAddresses} = $proxies;
  
  if (!$mailbox->SetAttributes(\%Attributes)) {
    print "Error setting 2K Attributes\n";
    exit 0;
 
  } else {
    print "Set Attributes correctly\n";
  }
}
 
Steven 
________________________________

From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
Conor Lillis
Sent: Thursday, September 22, 2011 4:02 AM
To: perl-win32-users@listserv.ActiveState.com
Subject: AD / ldap update



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

Reply via email to