I've done several small projects using ADSI (Win32::OLE) to do various tasks in Active Directory, such as create and delete users, groups, containers, add and remove users, etc. I have not done much with setting any attribute values, except for setting some attributes when creating objects. Now I need to set a value for an attribute and read it back later in the program. This should be simple to do, but it's not doing what I expect it to do. It's got to be something I'm doing wrong, but for the life of me I just can't see it. I have pasted a sample program below that demonstrates the problem.

I have tried this on two different domains, and with at least half a dozen different attributes, such as: description, displayName, adminDescription, company, etc. I realize that some of those attributes are multi-valued, and that if I was really trying to work with them I would need to use PutEX. I have tried printing Win32::OLE->LastError but it is always 0. I've also tried adding a GetInfo() after the SetInfo(), but to no avail. This code is correctly setting the value in active directory, but for the life of me I cannot see what the problem is. Could someone please tell me what I am doing wrong.

Here is the program:

use strict; use warnings; use diagnostics; use Win32::OLE; $Win32::OLE::Warn = 3; my $ldapStr="LDAP://CN=MyTest User,OU=Test,DC=ZZZZZZZZ,DC=local"; my $userObject = Win32::OLE->GetObject($ldapStr); print "$userObject->{displayName}\n"; $userObject->{displayName}="aaaabbbb"; $userObject->SetInfo(); print "$userObject->{displayName}\n";

And here is the output:

cccaaabbbcccddd ARRAY(0x52bf334)

The first value printed is correct, but I expect to see "aaaabbbb" as the second value. I would appreciate any guidance to what I need to do to fix this.


In reply to Setting Attribute Values with ADSI by ItsMe2003

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.