Link to home
Start Free TrialLog in
Avatar of Mirrorinc
Mirrorinc

asked on

VB Script to Disable AD User Accout

I need a VB Scrip that will allow a non admin user to quick disable a AD User account.  The Script needs to prompt the user for the persons first and last name to disable.  It will need to be able to crawel through all Sub OU's to find the user automatically.
What I have so far works like I want it, expect I have to sepecifiy the OU the user is located in which I don't want it needs to find the user by searching through all OU's


Const ADS_UF_ACCOUNTDISABLE = 2

' Prompt for user Common Name.
cn = InputBox("Enter the First & Last Name of the Employee you want to Disable Example: Firstname Lastname")

On Error Resume Next
Set objUser = GetObject _
    ("LDAP://cn=" & CN & ",ou=Facilities,ou=Production,dc=mirrorinc,dc=org")
If (Err.Number = 0) Then
    On Error GoTo 0
    intUAC = objUser.Get("userAccountControl")

    objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE
    objUser.SetInfo
Else
    On Error GoTo 0
    Wscript.Echo " User " & CN & " not found"
End If
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

Might be helpful for you. There is ready script for that with explanation
http://www.codeproject.com/KB/vbscript/Disable_Stale_AD_Users.aspx

Regards,
Krzysztof
Avatar of Mirrorinc
Mirrorinc

ASKER

that is all really good but way more code then I think I need.  I just need to know how to apply a Domain Wide Search for users to my Code Above.  I see from the link they are doing what I need but I need to know how to apply to my existing code.  I Haven't had to write to many scripts that access AD directly.
ASKER CERTIFIED SOLUTION
Avatar of jawa29
jawa29
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial