Delete Old computer accounts

' Delete Old computer accounts from AC

Dim OutPutFile
Dim FileSystem

Set FileSystem = WScript.CreateObject("Scripting.FileSyst

emObject")
Set OutPutFile = FileSystem.CreateTextFile("bad_comp_names.txt", True)

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."
OutPutFile.WriteLine Computer.Name
'Call DomainObj.Delete("Computer", Computer.Name)
End If
Next