Solved

Delete a list of computers from Active Directory

Posted on 2009-03-31
3
1,543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:
Mohamed Osama 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Here's a look at newsworthy articles and community happenings during the last month.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

688 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