Learn how to a build a cloud-first strategyRegister Now


Delete bulk AD account from text file

Posted on 2008-11-10
Medium Priority
Last Modified: 2012-06-27
Can someone help me with a script? I need a script to delete bulk AD contacts from text file. In text file the script has to read line by line. On each line there is a proxyaddress, the script has to find these proxyaddresses in AD and after delete it.

Question by:jefmelkenbeek
  • 4
  • 3
LVL 10

Expert Comment

ID: 22923284
* If you could use a csv file instead of a text file and then you might want to check the ADManager Plus tool from ManageEngine for this task:


Good Luck (^_^)

Author Comment

ID: 22928619
this is not what I'm looking for. I have already seen many bulk tools, but i have my own order of attributes in my csv or text file.

Author Comment

ID: 22996582
I was looking for another answer.
Is it possible to refund the points back?
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 10

Accepted Solution

Rudram earned 320 total points
ID: 23011202
* Sorry for the delay in getting back:

* Heres a script that could do the task:
Option Explicit
Dim oFSO, sFile, oFile, sText, obj
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set obj = GetObject("LDAP://CN=Users,dc=eu,dc=com")
sFile = "C:\Documents and Settings\Administrator.APDC01\Desktop\inputfile.txt"
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
 Do While Not oFile.AtEndOfStream
  sText = oFile.ReadLine
   If Trim(sText) <> "" Then
    Msgbox sText
    obj.Delete "user", "cn="&sText
   End If
WScript.Echo "The file was not there."
End If

Open in new window

LVL 10

Expert Comment

ID: 23011223
* Now in the above script;

* In line number 4: Replace the OU and domain structure as per your organization

* In line number 5: Replace the input file name and path for the same with your input file.

* In Line number 12, the attribute that has been taken into consideration is the Cannonical Name (CN) of the user property. Here you can replace it with any of the attributes that you want or is there in the input text file for the users; i.e. it may be the "mail" attribute (for email address) or the DN attribute for the distinguished name etc.

* And finally to see what all attributes for a user object is supported you can use a low level editing tool like ADSIEdit.msc and then using it drill down to the user obect as depicted in the ADUC console (you would find it in the domain partition part of the Adsiedit console) and the right click on that user and say properties and there check the box which says attributes with values and you can find all the attributes there.

Hope this helps (^_^)

Author Comment

ID: 23030273
Hello Rudram,

thanks a lot for your reponse.I will test it tomorrow:) and will let you know the result.

Author Closing Comment

ID: 31515057
Thanks for your code :).
it did the trick

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses

810 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