Solved

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

Posted on 2016-10-17
3
41 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
  • 2
3 Comments
 
LVL 78

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

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now