Sue D. Nymme has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Active Directory update weirdness
by NetWallah (Canon) on Jul 26, 2010 at 19:52 UTC | |
by Sue D. Nymme (Monk) on Jul 29, 2010 at 12:33 UTC | |
|
Re: Active Directory update weirdness
by bingos (Vicar) on Jul 27, 2010 at 19:35 UTC | |
by Sue D. Nymme (Monk) on Jul 29, 2010 at 12:41 UTC |