?
Solved

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

Posted on 2006-04-19
7
Medium Priority
?
1,077 Views
Last Modified: 2013-12-23
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?
0
Comment
Question by:jbell72
7 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 16489784
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.
0
 
LVL 32

Expert Comment

by:rsivanandan
ID: 16495281
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."
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."
End If
Next

set DomainObj=Nothing
set Shell=Nothing
Wscript.quit

Cheers!
Rajesh
0
 

Author Comment

by:jbell72
ID: 16495414
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 37

Expert Comment

by:bbao
ID: 16516273
you may consider to write a batch file or a piece of script to jointly use DSQUERY and NET USER.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 16516304
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
0
 

Author Comment

by:jbell72
ID: 16560164
This is great thanks, does anyonw knowhow to search just 1 OU not the entire domain?
0
 

Author Comment

by:jbell72
ID: 16560188
never mind got. How do I close a question?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A brief overview to explain gateways, default gateways and static routes OR NO - you CANNOT have two default gateways on the same server, PC or other Windows-based network device. In simple terms a gateway is formed when a computer such as a serv…
Many of us in IT utilize a combination of roaming profiles and folder redirection to ensure user information carries over from one workstation to another; in my environment, it was to enable virtualization without needing a separate desktop for each…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Screencast - Getting to Know the Pipeline

850 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