How can I use Active Directory queries to see if a computer has not been logged into for 30/60 days

I have ran queries in my OU to check which users have not logged in for 30/60/90 days. Does anyone know how to check to query computer objects that have not logged in for 30/60/90 days etc Windows Server 2003 and active directory tools?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can do that with dsquery.exe:
dsquery computer domainroot -limit 0 -inactive <number of weeks>
will give a list of computers that haven't logged on in <number of weeks> weeks.
Hi jbell72,

 Or alternatively you can use a VBScript to do it from any machine with admin priv.

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."
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."
end if

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

if err.number<>0 then
wscript.echo "Error connecting to " & DomainString
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."
End If

set DomainObj=Nothing
set Shell=Nothing

jbell72Author Commented:
I was looking for a rather simple approach using the AD tools. With users I can check who hant logged in in 60 days run the query and simply select all and then disable or delete. Can it not be dun in AD tools like this. Thaks for all ur answers as well.
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

bbaoIT ConsultantCommented:
you may consider to write a batch file or a piece of script to jointly use DSQUERY and NET USER.
You can pipe the dsquery result directly to dsrm:
dsquery computer domainroot -limit 0 -inactive 8 | dsrm
This should ask for each account inactive for more than 8 weeks if you want to delete it. For an automatic removal, add -noprompt.
If you want to be on the safe side, export the dsquery result to a text file ("remove.txt" in this example):
dsquery computer domainroot -limit 0 -inactive 8 >remove.txt
Then edit the file and make sure only accounts you want to remove are in the list.
Then run
type remove.txt | dsrm -noprompt

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jbell72Author Commented:
This is great thanks, does anyonw knowhow to search just 1 OU not the entire domain?
jbell72Author Commented:
never mind got. How do I close a question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.