Skip to main content
AD Academy
Back to all recipes
Level: JuniorLast updated:

Find computers that have not logged on for 90 days

$cutoff = (Get-Date).AddDays(-90)
Search-ADAccount -ComputersOnly -AccountInactive -TimeSpan 90.00:00:00 |
  Where-Object { $_.LastLogonDate -lt $cutoff } |
  Select-Object Name,LastLogonDate,DistinguishedName |
  Export-Csv stale-computers.csv -NoTypeInformation

Why it works this way

Stale computer accounts are needless attack surface and inventory noise.

Command breakdown

ParameterWhy it works this way
LastLogonDateReplicated, so accurate to about ±14 days. Check against every DC for precision.
AddDays(-90)The staleness threshold. 90 days is standard; 120 for field laptops.

Caution

Never delete straight away. Step 1: export the list. Step 2: disable and move to a separate OU. Delete only after 30 quiet days.

Watch out

  • Do not delete straight away: disable and park in a separate OU for a month.
  • Temporarily powered-off servers show up here too — verify first.

Similar recipes