Site icon Kommands.com

Finding Inactive Users and Computers in Active Directory (30-Day Check-In Report)

Inactive users and computers are a common security and housekeeping issue in Active Directory. This report identifies accounts that have not authenticated with AD in the last 30 days and presents the results in clear table format for easy review.


How inactivity is determined

Active Directory uses lastLogonTimestamp, which:


PowerShell Script (Table Output)

Import-Module ActiveDirectory

$DaysInactive = 30
$InactiveDate = (Get-Date).AddDays(-$DaysInactive)

# Inactive Users
$InactiveUsers = Get-ADUser `
    -Filter { lastLogonTimestamp -lt $InactiveDate -or -not lastLogonTimestamp } `
    -Properties lastLogonTimestamp, Enabled |
    Select-Object `
        Name,
        SamAccountName,
        Enabled,
        @{Name="LastLogonDate";Expression={
            if ($_.lastLogonTimestamp) {
                [DateTime]::FromFileTime($_.lastLogonTimestamp)
            } else {
                "Never"
            }
        }}

# Inactive Computers
$InactiveComputers = Get-ADComputer `
    -Filter { lastLogonTimestamp -lt $InactiveDate -or -not lastLogonTimestamp } `
    -Properties lastLogonTimestamp, Enabled |
    Select-Object `
        Name,
        Enabled,
        @{Name="LastLogonDate";Expression={
            if ($_.lastLogonTimestamp) {
                [DateTime]::FromFileTime($_.lastLogonTimestamp)
            } else {
                "Never"
            }
        }}

# Display Tables
Write-Host "`nInactive Users (30+ Days)`n"
$InactiveUsers | Sort-Object LastLogonDate | Format-Table -AutoSize

Write-Host "`nInactive Computers (30+ Days)`n"
$InactiveComputers | Sort-Object LastLogonDate | Format-Table -AutoSize

Sample Table Output

Inactive Users

NameSamAccountNameEnabledLastLogonDate
John DoejdoeTrue2025-11-02
Temp Usertemp.userFalseNever
Mary SmithmsmithTrue2025-10-29

Inactive Computers

NameEnabledLastLogonDate
WS-014True2025-10-28
OLD-LAPTOP-07FalseNever
LAB-PC-03True2025-11-01

How this table is typically used

Administrators commonly use this output to:


Notes

Do not rely on this for forensic timelines

“Never” usually means:

Account was created but never used

Computer was joined but never logged in

Always validate accounts before disabling or deleting

Exit mobile version