Solved

Delete a list of computers from Active Directory

Posted on 2009-03-31
3
1,540 Views
Last Modified: 2012-05-06
I have run the dsquery command to show me a list of all the 8 week inactive computers, but there are certain computers inactive that are in an OU I do not want to delete so I can't run the dsquery command to remove all inactive computers.

Is there a way to just delete a list of specific computer names in Active Directory, whether I create a text file with their names, or am able to exclude an OU when removing the machines?
0
Comment
Question by:garryshape
3 Comments
 
LVL 3

Assisted Solution

by:NPProjects
NPProjects earned 100 total points
ID: 24028649
I'd just go into active directory users and computers and select each pc while pressing ctrl.

By the time you have written a script you could be done.
0
 
LVL 23

Accepted Solution

by:
Admin3k earned 400 total points
ID: 24028808
If you would prefer scripting this one , please give this VBS script a go, please take the time to test it first


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\computers.txt", ForReading)
 
Const ForReading = 1
 
Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
 
'Then you can iterate it like this
 
For Each strLine in arrFileLines
set objComputer = GetObject("LDAP://CN=" & strLine & _
    ",CN=Computers,DC=fabrikam,DC=com")
objComputer.DeleteObject (0)
Next

Open in new window

0
 

Author Closing Comment

by:garryshape
ID: 31564798
The script helped with certain computers. But since a lot of the computers are in completely different OU's the script doesn't work for all the computers at once.

I've run the script for certain computers, and manually removed the other computers since it was faster than fixing a script to do so for me.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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 …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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