[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delete a list of computers from Active Directory

Posted on 2009-03-31
3
Medium Priority
?
1,551 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 400 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:
Mohamed Osama earned 1600 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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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 …
Suggested Courses

873 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