Active Directory update weirdness via OLE

Active Directory update weirdness via OLE

am 26.07.2010 14:55:39 von eroode

Hello all,

I am trying to update user information in Active Directory via
Win32::OLE, and I am seeing some behavior that confuses me.

Consider the following short program:

# ------------------------------------------------------------ ----
use Modern::Perl;
no warnings 'uninitialized';
use Win32::OLE;

my $ADsPath = 'LDAP://CN=Guest11,OU=OurDept,DC=OurDomain,DC=com';

my $user = Win32::OLE->GetObject($ADsPath);

# Some simple info
say 'Initial fetch';
my $uid = $user->sAMAccountName;
my $name = $user->Name;
my $phone = $user->telephoneNumber;
say " uid=$uid, name=$name, phone=$phone\n";
# This prints: uid=guest11, name=CN=Guest11, phone=000

# Update
$user->{telephoneNumber} = '555';
$user->SetInfo;

# ******************
# Re-display.
say 'After update';
$uid = $user->sAMAccountName;
$name = $user->Name;
$phone = $user->telephoneNumber;
say " uid=$uid, name=$name, phone=$phone\n";
# This prints: uid=guest11, name=CN=Guest11, phone=Guest11
# ******************

# Re-Fetch.
say 'Re-fetch';
$user = Win32::OLE->GetObject($ADsPath);
$uid = $user->sAMAccountName;
$name = $user->Name;
$phone = $user->telephoneNumber;
say " uid=$uid, name=$name, phone=$phone";
# This prints: uid=guest11, name=CN=Guest11, phone=555
# ------------------------------------------------------------ ----


This program
fetches a user object from AD,
prints three fields,
updates one of the fields,
prints the three fields again,
fetches the same object,
prints the three fields again.

Note the section that is set off with asterisks. After I change one
field's value and call SetInfo, the field appears to become corrupt.
In this case, it now holds the value of the displayName AD field. In
other cases, it prints "66048", which happens to be the value of the
userAccountControl AD field. The value that it prints seems to be
unpredictable.

Yet when I fetch the object again, it contains the correct value. And
when I look at the value in Active Directory, it is set properly, and
nothing seems to be corrupted.

What's going on here? Is a fetch always needed after a call to SetInfo?

Thanks,

-- Eric


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs