Solved

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

Posted on 2016-10-17
3
57 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 80

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

766 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