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?


In reply to Active Directory update weirdness by Sue D. Nymme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.