'Obsolete_computer_accounts.vbs
'v1.5
'last modified April 2004
'Jeffery Hicks
'[email protected]
'http://www.jdhitsolutions.com
'Usage: cscript obsolete_computer_accounts.vbs
'Desc: Determine Obsolete Computer Accounts with user specified cutoff date
'You must have Domain Admin rights to properly use this script.
'You should use CSCRIPT to run this or you will get many, many
'dialog boxes.
' *********************************************************************************
' * THIS PROGRAM IS OFFERED AS IS AND MAY BE FREELY MODIFIED OR ALTERED AS *
' * NECESSARY TO MEET YOUR NEEDS. THE AUTHOR MAKES NO GUARANTEES OR WARRANTIES, *
' * EXPRESS, IMPLIED OR OF ANY OTHER KIND TO THIS CODE OR ANY USER MODIFICATIONS. *
' * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB *
' * ENVIRONMENT. USE AT YOUR OWN RISK. *
' *********************************************************************************
On Error Resume Next
dim DomainObj
dim wnet
set wnet=CreateObject("wscript.network")
DomainString=wnet.UserDomain
numDays=InputBox("What is the number of days for password age to use as a cutoff for Active Computer Accounts? NO computer accounts will be deleted.","Check Active Computers","45")
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.echo "Err#" & err.number & " " & err.description
wscript.quit
end if
DomainObj.Filter = Array("computer")
Wscript.echo "Computer Accounts in " & DomainString & " older than " & numDays & " days based on password age."
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.)"
End If
Next
set DomainObj=Nothing
Wscript.quit
'EOF
|