Hi, I need some help disabling Active Directory users with NET::LDAP. I am able to connect to the User and modify/add other values.

looking here, http://support.microsoft.com/kb/305144, it says that the userAccountControl flag for disabled is 2, but if I look in ADSI edit it seems that disabled accounts have the userAccountControl set as 514. I cant seem to set either of those values in my script.

Here is a bit of my code

$res = $ldap->modify ($distinguishedName, # delete and readd the userAccountControl # this will disable the account delete => {userAccountControl=> []}, add => {userAccountControl => "514"} ); # if there is an error stop and let us know if ( $res->code()) { die ("error: ", $res->code(),"\n", "error name: ",$res->error_name(),"\n", "error text: ",$res->error_text(),"\n"); }

The error I receive from the above code is;
error:53
error name: LDAP_UNWILLING_TO_PERFORM
error text: The server is unwilling to perform the requested operation

I guess the way I am trying to modify the userAccountControl attribute is not supported but I am not sure how to go about changing it.
I can change the value in ADSI edit and it enables/disables accounts ok but maybe it is hiding the actual process.
Any help is appreciated.


In reply to NET::LDAP disable AD user by OldManYoss

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.