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=Product ion,dc=mir rorinc,dc= org")
If (Err.Number = 0) Then
On Error GoTo 0
intUAC = objUser.Get("userAccountCo ntrol")
objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE
objUser.SetInfo
Else
On Error GoTo 0
Wscript.Echo " User " & CN & " not found"
End If
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=Product
If (Err.Number = 0) Then
On Error GoTo 0
intUAC = objUser.Get("userAccountCo
objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE
objUser.SetInfo
Else
On Error GoTo 0
Wscript.Echo " User " & CN & " not found"
End If
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.codeproject.com/KB/vbscript/Disable_Stale_AD_Users.aspx
Regards,
Krzysztof