Deleting old computer accounts in AD

D

Dave Beverly

Does anyone know of a way to "scavange" AD to delete old
computer accounts? Hoping not to have to do this by
hand... Thanks!
 
J

JB

Or you can use this .vbs that I found and modified it so that it will
dump the info to a oldcomputer.txt file on your c:\ drive. Just copy
the info below and and save it as a .vbs, Then launch the vbs it will
prompt you for your domain and then it will prompt you for how may
days old. Then just open the txt file to get the info. You can then
create a another script to delete the computer accounts that are "out
of date"


'==================================
'On Error Resume Next

DomainString=Inputbox("Enter the domain name","Check Active
Computers","DomainName")

if DomainString="" then
wscript.echo "No domain specified or script cancelled."
wscript.quit
end if

numDays=InputBox("What is the number of days to use as a cutoff for
Active Computer Accounts?","Check Active Computers","XX")

if numDays="" then
wscript.echo "No cutoff date specified or script cancelled."
wscript.quit
end if

Set DomainObj = GetObject("WinNT://"&DomainString)

if err.number<>0 then
wscript.echo "Error connecting to " & DomainString
wscript.quit
end if

DomainObj.Filter = Array("computer")
Wscript.echo "Computer Accounts in " & DomainString & " older than " &
numDays & " days."
For each Computer in DomainObj
Set Account = GetObject("WinNT://" & DomainString & "/" &
Computer.Name & "$")
RefreshTime = FormatNumber((Account.get("PasswordAge"))/86400,0)
If CInt(RefreshTime) >= CInt(numDays) Then
'wscript.echo "**DELETE** " & Computer.Name & " Password Age is " &
RefreshTime & " days."
On Error Resume Next
Dim FileSys,TFile

Set FileSys = CreateObject("Scripting.FileSystemObject")

Set TFile = FileSys.CreateTextFile("C:\Oldcomputers.txt", True)

TFile.WriteLine "**DELETE** " & Computer.Name & " Password Age is "
& RefreshTime & " days."

End If
Next

TFile.Close

set DomainObj=Nothing
set Shell=Nothing
Wscript.quit
'==================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top