active directory users

Is there some sort of program I can run or a script (not sure if that is what it is) that will tell me the users and computers in active directory that have not logged onto the system using in between dates?  I am looking to delete some of them that are no longer needed.  Clean it up a little.  Any ideas?
mkramer777Asked:
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.

Will SzymkowskiSenior Solution ArchitectCommented:
You can do this using powershell. 2 scripts one for Users and one for Computers. See below...

The scripts below will find all users and computers that are less then a month but greater than 5 months.

Users
Import-module activedirectory
$date = get-date
Get-ADUser -Filter * -Properties name, LastLogonDate, DistinguishedName | ? {$_.LastLogonDate -lt $date.AddMonths(-1) -and $_.LastLogonDate -gt $date.AddMonths(-5) } |
Select Name, LastLogonDate, DistinguishedName |
Export-Csv "c:\inactiveUsers.csv" -nti

Open in new window


Computers
Import-module activedirectory
$date = get-date
Get-ADComputer -Filter * -Properties name, LastLogonDate, DistinguishedName | ? {$_.LastLogonDate -lt $date.AddMonths(-1) -and $_.LastLogonDate -gt $date.AddMonths(-5) } |
Select Name, LastLogonDate, DistinguishedName |
Export-Csv "c:\inactiveComputers.csv" -nti

Open in new window


Will.
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
Or you can use the command line tool DSQUERY.

DSQUERY user -inactive 13

Should display a list of users who have been inactive for the last 13 weeks (3 months)

Reference DSQUERY /? or http://ss64.com/nt/dsquery-user.html
0
mkramer777Author Commented:
Is there a dsquery for computers?
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
Yes, as I said, run DSQUERY /? or visit the link I provided and click on "DSQUERY".
0

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
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
Active Directory

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.