In short
- Inactive users: use
LastLogonDatewith a 90-day cutoff, but remember it can lag by up to two weeks, and catch accounts that have never signed in separately. - Stale computers: combine the last sign-in with the machine password age; active computers change their password every 30 days.
- Privileged accounts: list the recursive members of every powerful group, then look for leftovers marked
AdminCount=1. - Clean up in stages: disable, wait, then delete. Never delete on day one.
Why stale accounts matter
Every enabled account is a username and a working password. When the person or system behind it has gone, nobody notices if it is used, nobody changes its password, and it often still has the access it had years ago. Attackers love these accounts: password-spraying finds the weak ones, and signing in with them rarely raises an alarm.
Privileged accounts are the other half of the picture. The question isn’t only “who is in Domain Admins?” but who effectively has admin rights through nested groups, operator groups and leftovers from old projects.
Which sign-in date to trust
| Attribute | What it is | Use it for |
|---|---|---|
lastLogonTimestamp(shown as LastLogonDate) | Replicated to every domain controller, but only updated about every 9–14 days | Finding accounts inactive for 30, 60 or 90 days |
lastLogon | Exact time, but stored separately on each domain controller and not replicated | Checking one account precisely before you disable it |
PasswordLastSet | When the password last changed. Computers change theirs automatically every 30 days by default | Confirming a computer really is gone |
So a 90-day cutoff on LastLogonDate is safe: two weeks of lag doesn’t matter at that scale. Don’t use it to prove someone signed in yesterday.
Inactive and never-used users
All commands need the RSAT Active Directory module and only read from AD. Set the cutoff once:
Import-Module ActiveDirectory
$cutoff = (Get-Date).AddDays(-90)
Enabled users who haven’t signed in for 90 days:
Get-ADUser -Filter 'Enabled -eq $true -and LastLogonDate -lt $cutoff' `
-Properties LastLogonDate, PasswordLastSet, whenCreated, Description |
Select-Object SamAccountName, Name, LastLogonDate, PasswordLastSet, whenCreated, Description |
Sort-Object LastLogonDate |
Export-Csv .\inactive-users.csv -NoTypeInformation
Enabled users who have never signed in, created more than 90 days ago. The first query misses these, because an empty date isn’t “older than” anything:
Get-ADUser -Filter 'Enabled -eq $true' -Properties LastLogonDate, whenCreated |
Where-Object { -not $_.LastLogonDate -and $_.whenCreated -lt $cutoff } |
Select-Object SamAccountName, Name, whenCreated
Check one account exactly before you act, by asking every domain controller:
$user = 'jdoe'
Get-ADDomainController -Filter * | ForEach-Object {
$u = Get-ADUser $user -Server $_.HostName -Properties lastLogon
[pscustomobject]@{ DC = $_.Name; LastLogon = [DateTime]::FromFileTime($u.lastLogon) }
} | Sort-Object LastLogon -Descending | Select-Object -First 1
Expect some false alarms: service accounts that only run scheduled tasks, accounts used by applications through LDAP, and emergency (“break-glass”) accounts. Mark these in the Description field so next month’s report is shorter.
Stale computers
A computer is very likely gone when it has neither signed in nor changed its machine password for 90 days:
Get-ADComputer -Filter 'Enabled -eq $true' -Properties LastLogonDate, PasswordLastSet, OperatingSystem |
Where-Object { $_.LastLogonDate -lt $cutoff -and $_.PasswordLastSet -lt $cutoff } |
Select-Object Name, OperatingSystem, LastLogonDate, PasswordLastSet |
Export-Csv .\stale-computers.csv -NoTypeInformation
Before disabling, check the name against your asset list, DHCP and antivirus console. Laptops that are away for long periods, and cluster or appliance accounts, are the usual exceptions.
Privileged accounts
Look beyond Domain Admins. These built-in groups can all lead to full control of the domain, directly or in a few steps:
$groups = 'Domain Admins','Enterprise Admins','Schema Admins','Administrators',
'Account Operators','Server Operators','Backup Operators','Print Operators',
'DnsAdmins','Group Policy Creator Owners'
$priv = foreach ($g in $groups) {
Get-ADGroupMember -Identity $g -Recursive -ErrorAction SilentlyContinue |
Where-Object objectClass -eq 'user' |
Get-ADUser -Properties LastLogonDate, PasswordLastSet, PasswordNeverExpires |
Select-Object @{n='Group';e={$g}}, SamAccountName, Enabled, LastLogonDate,
PasswordLastSet, PasswordNeverExpires
}
$priv | Sort-Object SamAccountName | Format-Table -AutoSize
Go through the list with someone who knows the team. For each account ask:
- Is this a named person, and do they need this today? Operator groups are usually best left empty.
- Is it disabled or inactive? A disabled admin account should leave the group; an inactive one should be disabled.
- Is the password more than a year old, or set to never expire?
- Is it a service account? Service accounts almost never need to be domain admins.
$priv | Where-Object { -not $_.Enabled -or $_.LastLogonDate -lt $cutoff -or
$_.PasswordLastSet -lt (Get-Date).AddYears(-1) }
Group membership is not the only way to be powerful. Rights such as replicating passwords (DCSync), full control over admin accounts or over Group Policy, and risky certificate templates can make an ordinary-looking account a domain admin in all but name. These are hard to see by hand; that’s where an assessment tool helps.
Former admins: AdminCount leftovers
When an account joins a protected admin group, AD sets AdminCount=1 on it and locks down its permissions. When it leaves the group, neither is undone automatically. These “former admins” are often forgotten and keep unusual permissions.
$current = $priv.SamAccountName | Sort-Object -Unique
Get-ADUser -Filter 'AdminCount -eq 1' -Properties LastLogonDate |
Where-Object { $_.SamAccountName -notin $current -and $_.SamAccountName -ne 'krbtgt' } |
Select-Object SamAccountName, Enabled, LastLogonDate
For each one, confirm it really shouldn’t be privileged, then clear AdminCount and turn permission inheritance back on (Active Directory Users and Computers → Security → Advanced) so it is managed like every other account.
A safe clean-up process
- Export and share the list with managers or system owners, with a date for objections.
- Disable, don’t delete. Add a note to the description, such as
Disabled 2026-11-17 - inactive 90d - ticket 1234, and move the object to a “Disabled” OU. - Wait 30–90 days. If something breaks, re-enable it in seconds; nothing is lost.
- Delete after the waiting period. With the AD Recycle Bin enabled, even a deletion can be undone for a while.
- Remove privileges first. For admin accounts, take them out of privileged groups as soon as they are confirmed unneeded, even before the account itself is disabled.
Doing it every month
Stale accounts come back as people leave and projects end, so this is a monthly job, not a one-off. You can schedule the scripts above, or let BindShield do it: its Stale objects and Privileged accounts areas cover inactive users and computers, accounts with no password required, admin group membership, Kerberoastable admins, DCSync rights and delegation, and the Professional licence compares each run with the last so you can see what changed.
Download BindShield free See the full AD security checklist
Related: Free Active Directory security assessment: what to check and how.
Want help with the clean-up?
Our infrastructure and security team can review the findings with you and run the clean-up safely. Write to [email protected] or use our contact form.