Mass ID disablement in Active Directory

Posted on 2006-06-21
Last Modified: 2010-08-05
anybody knows how to write a script to disable and delete multiple IDs (abt 2000) in windows 2000 Active Directory?

- one line of statement (which means NOT 2000 command line which refer to individual ID).
- the script should refer to a text file or excel file for the ID listing

appreciate yr help. I need this urgently.

thanks in advance
Question by:yatie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 16951191
You probably already know this but just in case; deleting things using scripts can get you into trouble.

You are wanting to remove(delete) user accounts from AD or disable them or both? Will there be computer accounts as well or just users? Please provide a little more detail as to what you want you script to accomplish.


Author Comment

ID: 16956424
Hi Krompton,

Thanks for the response. What I wanna do is:
i) to disable user accounts from AD (no computer accounts, only user accounts)
ii) after two weeks, run another script to disable those disabled user accounts
iii) have a script which single or few lines BUT NOT individual user account as 1 line of command

Thanks very much. Hope you could help me achieve this.


Accepted Solution

Krompton earned 125 total points
ID: 16961351
Disabling accounts via script is reasonably easy and the script would only need to be a few lines long. The “difficult” part is if you want to use a script to get the usernames. You’ll need some criterion that will filter the accounts.

Is there something the same in all the accounts to be disabled and NOT in those to be left alone?

If your answer to this question is “no” then try this:
I know this works for 2003 but have not tried it on 2000


Run the following command on your Domain Controller
dsquery user > "C:\DomainUserList.txt" (EDIT the text file created and delete users you don’t want disabled)
(dsquery.exe should be located in c:\windows\system32 folder)

Save text between **** as .vbs (i.e. C:\DisableUsers.vbs)

 UsageMsg = "Usage: " & VBCrLf & "          WScript.exe C:\DisableUsers.vbs UserListToDisable DNSNameOfDomainController" & VBCrLf & _
"Example:" & VBCrLf & "          WScript.exe C:\DisableUsers.vbs C:\DomainUserList.txt DC1.Domain.Local"

Const ADS_UF_ACCOUNTDISABLE = 2, ForReading = 1, ForWriting = 2, ForAppending = 8
If WScript.Arguments.Count < 2 Then
      MsgBox UsageMsg,,"Syntax Error"
      UserListFile = WScript.Arguments(0)
      Controller = WScript.Arguments(1)
End If
Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
Set oFSContents = oFS.OpenTextFile(UserListFile, ForReading)
UserList = oFSContents.ReadAll
Users = Split(UserList, vbNewLine)

For Each User in Users
      If User <> "" Then
            Set objUser = GetObject("LDAP://" & Controller & "/" & (Replace(User, Chr(34), "")))
            intUAC = objUser.Get("userAccountControl")
            objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE
      End If



Then run the following command on your Domain Controller
WScript.exe C:\DisableUsers.vbs C:\DomainUsers.txt DNSNameOfDomainController

Good Luck,

Expert Comment

ID: 16962293
Oh, BTW...

          Set objUser = GetObject("LDAP://" & Controller & "/" & (Replace(User, Chr(34), "")))
          intUAC = objUser.Get("userAccountControl")
          objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE

      Set WSHShell = CreateObject("Wscript.Shell")
      Cmd = "cmd /c dsrm -noprompt " & User
      MyVal = WSHShell.Run(Cmd,1,True)

When you want to delete the users.

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question