Listing06_Manipulate_Object_Net-LDAP (Perl)

This code can be found in Chapter 3 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# -------------------------------------------------------------------
# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4
# Copyright (C) 2002 by Addison-Wesley
# Script by Robbie Allen
# -------------------------------------------------------------------
#
# Add jdoe user
$result = $ldap->add (
    dn   => 'cn=jdoe,cn=users,dc=xyz,dc=com',
    attr => [
     cn      => 'jdoe'',
     samaccountname    => 'jdoe',
     userprincipalname => 'jdoe@xyz.com',
     mail              => 'jdoe@xyz.com',
     telephoneNumber   => '911',
     objectclass       => ['user'],
    ],
);
die $result->error if $result->code;
# Modify attributes of jdoe
$result = $ldap->modify('cn=jdoe,cn=users,dc=xyz,dc=com',
    changes => [
     add     => [ sn => 'Doe' ], # populate sn attribute
     delete  => [ telephoneNumber => '911'], # remove '911' telephoneNumber entry
     replace => [ mail => 'John.Doe@xyz.com'], # change email address
    ]
);
die $result->error if $result->code;
# Delete jdoe
$result = $ldap->delete("cn=jdoe,cn=users,dc=xyz,dc=com");
die $result->error if $result->code;

This code has been viewed 850 times.

New from the creators of TechTasks.com: StatSheet.com