I'd like to be able to enable/disable a specific domain account in AD using
a script. Does anyone know if this can be done?

Thanks!

Re: Script to enable/disable domain account? by Brandon

Brandon
Fri Feb 18 00:20:20 CST 2005



"D.P. Roberts" wrote:

> I'd like to be able to enable/disable a specific domain account in AD using
> a script. Does anyone know if this can be done?

No to demean you or anything because that isn't my intent but this is one of
the easiest things to do with AD.
The following comes from chapter 6 of the AD cookbook(GUI and CLI methods are
included, script is at bottom):

Recipe 6.12 Enabling and Disabling a User
6.12.1 Problem
You want to enable or disable a user.

6.12.2 Solution
6.12.2.1 Using a graphical user interface
Open the Active Directory Users and Computers snap-in.

In the left pane, right-click on the domain and select Find.

Select the appropriate domain beside In.

Type the name of the user beside Name and click Find Now.

In the Search Results, right-click on the user and select Enable Account to
enable or Disable Account to disable.

Click OK.

6.12.2.2 Using a command-line interface
To enable a user, use the following command:

> dsmod user <UserDN> -disabled no
To disable a user, use the following command:

> dsmod user <UserDN> -disabled yes


6.12.2.3 Using VBScript
' This code will enable or disable a user.
' ------ SCRIPT CONFIGURATION ------
' Set to FALSE to disable account or TRUE to enable account
strDisableAccount = FALSE
strUserDN = "<UserDN>" ' e.g. cn=jsmith,cn=Users,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------

set objUser = GetObject("LDAP://" & strUserDN)
if objUser.AccountDisabled = TRUE then
WScript.Echo "Account for " & objUser.Get("cn") & " currently disabled"
if strDisableAccount = FALSE then
objUser.AccountDisabled = strDisableAccount
objUser.SetInfo
WScript.Echo "Account enabled"
end if
else
WScript.Echo "Account currently enabled"
if strDisableAccount = TRUE then
objUser.AccountDisabled = strDisableAccount
objUser.SetInfo
WScript.Echo "Account disabled"
end if
end if