Link to home
Start Free TrialLog in
Avatar of mkramer777
mkramer777Flag for United States of America

asked on

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?
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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.
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
Avatar of mkramer777

ASKER

Is there a dsquery for computers?
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial