Case File: The Accounts Nobody Uses
The audit asks how many accounts belong to people who left. Classify every account in a directory export as disabled, never used, stale, a password that never expires, or ok, using exact day limits and the 14-day lag of lastLogonTimestamp, and list the accounts to disable. Check the edges on exports you cannot see. The accounts are generated for you alone.
Sabi Logistics · Domain 1
The Accounts Nobody Uses
The auditor found a working account for a driver who left two years ago, and asks how many more there are
Musa Head of IT · Phone call
Musa. The auditor logged in with an account that belongs to a driver who left two years ago. Nobody had disabled it, and its password never expires. The question that I could not answer was: “How many more like it do you have?”
Here is an export of the user accounts: logon name, whether it is enabled, the date of the last logon, the date that it was created, and whether the password never expires. I want each account classified, with rules that I can explain to the auditor, and the list of accounts to disable. One more thing: the IT consultant told me that the “last logon” date is not exact. Please account for that.
The brief
What you need to know first.
- Why the date is not exact. The attribute that most tools read,
lastLogonTimestamp, is only updated when its old value is more than 14 days old, so that every logon does not create replication traffic. It can be up to 14 days behind the truth. A rule of “90 days of inactivity” must therefore use90 + 14 = 104days, so that you never disable somebody who logged in on day 91. - The classes, the first rule that applies: disabled (not enabled: leave alone); never_used (enabled, no logon at all, and created more than 30 days ago; a newer account may simply belong to somebody who has not started yet, so it is
ok); stale (the last logon is more than 104 days ago); pwd_never_expires (not stale, but the password never expires); otherwise ok. - Dates.
date.fromisoformat(...)and(today - d).days. Compare with>: exactly 104 days is not stale, 105 is; exactly 30 days is not never_used, 31 is. - Return
{"classes": {name: class}, "to_disable": sorted names of the never_used and stale accounts}. Disabled accounts are not into_disable. - Fill in
classify(today, user),review(req),resultandcounts. The checks runreviewon exports that you cannot see, including every edge and an empty export.
The lab gives you the data for this case, invented and generated for you alone. Today is 2026-11-09.
Preparing your data…
On a real system
The lab modelled the rules with a script. These are the commands that you would type on the real thing.
| You want to | Type | What you get |
|---|---|---|
| find accounts that have not been used for 90 days | Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly | enabled and disabled user accounts that are inactive |
| check the last logon date of every account | Get-ADUser -Filter * -Properties LastLogonDate | Select-Object Name, LastLogonDate | a date that can be up to 14 days behind the truth |
| disable an account | Disable-ADAccount -Identity jdoe | the account can no longer sign in |
Only run commands on systems that you own or have written permission to test.
Musa: “Eleven accounts to disable. A manager says that two of them are seasonal drivers who come back in December. How do we avoid locking out real people?”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Musa: “So we disable first, delete much later, and ask the managers before.”
What a senior administrator would do next. Disable, do not delete: move the account to a “Disabled” OU, record the date and the reason in the description, and delete after a retention period (90 days or more), once nobody has complained. Send the list to the managers for the accounts of their people before the change. Handle seasonal and long-leave staff with an expiry date on the account (Set-ADAccountExpiration) and a renewal. Treat service accounts separately: they have no human logon, may never log on interactively, and must not be disabled by this rule; they need an owner and managed service accounts (gMSA) where possible. Automate the report monthly, and connect it to the HR leavers list, since the right moment to disable an account is the day the person leaves, not 104 days later. Fix “password never expires” where it is not needed. And remember that a stale account is also a security finding: it is a login that nobody is watching.
The trap. Trusting the last logon date to the day. The date is a hint that is up to two weeks old.
Write the account audit note
Write the note for the Head of IT: the classes and the exact rules, why 104 days and not 90 (the 14 day lag of lastLogonTimestamp), why never-used accounts have a grace period of 30 days, how many accounts are in each class and which are to be disabled, how to disable safely (a Disabled OU, a reason and date, a retention period, manager review, account expiry for seasonal staff), and how to keep it from coming back (service accounts and gMSA, the HR leavers list, a monthly report).
🧪 Want to practise this on your own computer? See how to set up your lab →