We help IT Professionals succeed at work.

delete users

please How can I delete the list of users in active directory
Watch Question

Little more clarity required...
Do you want to delete them all? do you want to delete all of the users that meet a certain criteria?
Elaborate a little please

Realizing that if you delete the user in active directory then that user can no longer log on/authenticate to the directory


I mean delete the users in different OU's and I want to process a large number of users from a text file, (e.g:via vbscript).
Sure thing,
You probably want to do it with powershell
check out this thread, i have used the script before and it worked well

It does require that you ahve powershell and the Quest AD extensions installed (Download here if you don't have them ... http://www.quest.com/powershell/activeroles-server.aspx)

Basiccally you are importing the csv list of users, then "foreach" of them, delete the user
I have modified it to only worry about the user account:
$_.userName refers to a column in the file "users.csv" titled userName, the -whatif asks if you are sure
import-csv users.csv | foreach {

# get a reference to the user's account
$user = Get-QADUser $_.userName

# delete the user object
Remove-QADObject -identity $user -force -whatIf

Open in new window


you have the code in the vbscript please
Sorry I don't, I use Powershell due to it's awesome AD integration that is made even better by the quest extensions


the code is not working
in attachement
import-csv users.csv | foreach {

# get a reference to the user's account
$user = Get-QADUser $_.userName

# delete the user object
Remove-QADObject -identity $user -force -whatIf

Open in new window

Is there an error?
Did you install the quest extensions and launch their powertel environment ti run it?
hirenvmajithiyaManager (System Administration)

Try AD Manager Plus(trial version), it will serve the purpose.
Hi all,

DRRAM, Then you can delete the users group wise..

' VBScript to discover the members of a Group

strDomain = InputBox ("Enter Domain Name")

strGroup =  InputBox ("Enter Group Name")

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True


intRow = 2


objExcel.Cells(1, 1).Value = "User Name"

Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup)

Set strMembers = objGroup.Members

For Each strMember In strMembers

objExcel.Cells(intRow, 1).Value = strMember.Name

intRow = intRow + 1




objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True



Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

Set objRange = objExcel.Range("A1")

objRange.Sort objRange,1,,,,,,1


MsgBox "Done"

Thank you

Edit the location of the text file, which must contain the usernames you want to delete
This will delete the user from active directory, regardless of the OU they are in.
An output log file will let you know if it was successful or not

Dim strUser, rootDSE, adoConnection, ldapStr, adoRecord, objUser
Const ForReading = 1

'set variables here for easy modification
strTxtFile = "C:\support\userlist.txt" 'input text file
strOutputFile = "C:\support\users_deleted.txt" 'file for output

Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.OpenTextFile(strTxtFile, ForReading) 'open file for reading
Set objOutputFile = fso.CreateTextFile(strOutputFile) 'create text file for output

Set rootDSE = GetObject("LDAP://RootDSE")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "ADs Provider"

Do Until objFile.AtEndOfStream
	found = false
	strUser = objFile.ReadLine
	ldapStr = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">;(&(objectCategory=person)(objectClass=user)(cn=" & strUser & "));adspath;subtree"
	Set adoRecord = adoConnection.Execute(ldapStr)
	If Not adoRecord.EOF Then
		found = true
		Set objUser = GetObject (adoRecord.Fields(0).Value)
		objUser.DeleteObject (0)
		objOutputFile.writeline Right(objUser.name,Len(objUser.name)-3) & ", has been deleted"
	End If
	If found = false then
		objOutputFile.writeline strUser & ", was not found in AD"
	End if

wscript.echo "Script finished"

Open in new window


thx very much " Scottyworld" please
To delete the pcs I can use the same code
how I can adapt this code
It's pretty much the same change as the last code I gave you! A very simple change here...
On line 20,
That's it!


Thanks very much for the good support "Scottyworld"
No problem, happy to help out