PS script for report of accounts havent logged in for a long time

Is there a powershell script that can run a report against active directory to seek and find accounts who havent logged into the forest in a long time?
Rammy CharlesSales EngineerAsked:
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.

AmitIT ArchitectCommented:
You can check last long time for user using PS. Check this Script:
https://gallery.technet.microsoft.com/scriptcenter/Get-Active-Directory-user-246f17c7

Test it.
Shaun VermaakTechnical SpecialistCommented:
austin minorCommented:
Powershell to find inactive accounts Active Directory for 90 days or longer.

Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 90 | ?{$_.enabled -eq $True} | Get-ADUser -Properties Name, EmailAddress, Department, Description, lastLogonTimestamp | Select Name, EmailAddress, Department, Description,@{n='lastLogonTimestamp';e={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | Export-Csv D:\temp\testfunytest.csv


Source:  http://expert-advice.org/active-directory/powershell-to-find-inactive-ad-users-and-computers-accounts/

You can also automate this process using this Active Directory cleanup solution like; Lepide, OldCmp and ManageEngine to identify, move or clean up inactive AD user accounts.

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
Rammy CharlesSales EngineerAuthor Commented:
austin that is what i wanted. do you oknow if i can add filters to not show some accounts on the report and also how can i sort by lastlogontimestamp?
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
You filter the results by using Where-Object (aka ?). So if you have a list of users you could match the current name against it.
And sorting is easy enough. Sort-Object <property name>.  Putting it together is something like this:
$userfilter = Get-Content C:\filterlist.txt
Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 90 | ?{$_.enabled -eq $True} | Get-ADUser -Properties Name, EmailAddress, Department, Description, lastLogonTimestamp | ?{$userfilter -notmatch $_.SamAccountName} | Select Name, EmailAddress, Department, Description,@{n='lastLogonTimestamp';e={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | sort lastlogontimestamp | Export-Csv D:\temp\testfunytest.csv

Open in new window

Note the additions of
$userfilter = Get-Content C:\filterlist.txt
?{$userfilter -notmatch $_.SamAccountName}
sort lastlogontimestamp

Be sure to edit for your environment.
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
Powershell

From novice to tech pro — start learning today.