Solved

Delete a list of computers from Active Directory

Posted on 2009-03-31
3
1,532 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

Join & Write a Comment

Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
Resolve DNS query failed errors for Exchange
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now