Solved

PowerShell Script - List users that have not logged on in the past 3 months

Posted on 2016-10-17
3
62 Views
Last Modified: 2016-10-19
Does anyone have a PowerShell script that can list users in AD that have not logged on in the past 3 months?
0
Comment
Question by:amazon4life
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 81

Expert Comment

by:David Johnson, CD, MVP
ID: 41847420
import-module ActiveDirectory
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 | where {$_.ObjectClass -eq 'user'} | FT Name,ObjectClass –A

Open in new window

0
 
LVL 6

Accepted Solution

by:
Niten Kumar earned 500 total points
ID: 41847712
# List all users in that have not logged on within  
# XXX days in "Active Directory"  
#  
# This script requires the Active Directory Module from Microsoft.  
# It works with Server 2008 R2 and higher Domain Controllers
#
# Get the Current Date  
#  
$CurrentDate=GET-DATE  
#  
# Number of Days to check back.    
#  
$NumberDays=90  
#  
# Organizational Unit to search  
#  
$SearchBase='OU=Users,OU=Business,DC=Contoso,DC=Local'  
#  
Import-Module ActiveDirectory
GET-ADUSER -filter * -SearchBase $OU -properties LastLogonDate | where { $_.LastLogonDate.AddDays($NumberDays) -lt $CurrentDate } | Format-Table
0
 
LVL 6

Expert Comment

by:Niten Kumar
ID: 41847723
You can also try the following script:

Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 | ?{$_.enabled -eq $true} | %{Get-ADUser $_.ObjectGuid} | select name, givenname, surname | export-csv c:\report\unusedaccounts.csv -NoTypeInformation
1

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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