Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Delete Computer Accounts in AD

Status
Not open for further replies.

Gopi Krishna

Member
Messages
22
Reaction score
0
Points
1
Hi,

I have a text file with the list of 3000 computer names and I have to delete them all from AD.
How can I do this bulk deletion? Please Help

Thank you,
 
Solution
You can try any of these :-

https://gallery.technet.microsoft.com/scriptcenter/Bulk-Delete-computers-in-24819345

or

Code:
Const SourceFile = ".\computers.ini"

On Error Resume Next
Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set oSourceFile = objFSO.OpenTextFile(SourceFile, 1)

While oSourceFile.AtEndOfStream <> True
   strComputer = oSourceFile.ReadLine
   set objComputer = GetObject("LDAP://CN=" & strComputer & _
          ",CN=Computers,DC=fabrikam,DC=com")
   objComputer.DeleteObject (0)
   If Err.Number <> 0 Then
     Wscript.Echo "Error deleting " & strComputer & "."
     Err.Clear
   Else
     Wscript.Echo strComputer & " was succesfully deleted."
   End If
Wend
You can try any of these :-

https://gallery.technet.microsoft.com/scriptcenter/Bulk-Delete-computers-in-24819345

or

Code:
Const SourceFile = ".\computers.ini"

On Error Resume Next
Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set oSourceFile = objFSO.OpenTextFile(SourceFile, 1)

While oSourceFile.AtEndOfStream <> True
   strComputer = oSourceFile.ReadLine
   set objComputer = GetObject("LDAP://CN=" & strComputer & _
          ",CN=Computers,DC=fabrikam,DC=com")
   objComputer.DeleteObject (0)
   If Err.Number <> 0 Then
     Wscript.Echo "Error deleting " & strComputer & "."
     Err.Clear
   Else
     Wscript.Echo strComputer & " was succesfully deleted."
   End If
Wend
 
Solution
I copied the above script and ran it as .vbs Script in the DC and saved all the list of computers to be deleted in "computers.ini" file.
But now it is giving error saying "Error Deleting <Computer name>"
And none of the computers are deleted.
Am I doing it wrong?
 
Have you tried the first link ?. You can run this script on member server rather than running on AD server.
 
Status
Not open for further replies.

Forum statistics

Threads
7,027
Messages
27,499
Members
17,680
Latest member
Symetria
Back
Top