ItsMe2003 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Setting Attribute Values with ADSI
by GrandFather (Saint) on Jan 01, 2012 at 00:01 UTC | |
by ItsMe2003 (Initiate) on Jan 01, 2012 at 08:54 UTC | |
|
Re: Setting Attribute Values with ADSI
by NetWallah (Canon) on Jan 01, 2012 at 06:04 UTC | |
by ItsMe2003 (Initiate) on Jan 02, 2012 at 05:28 UTC |