Skip to content
Menu

Stale AD Users and Computers - Who Has Not Signed in for 90 Days

Lists enabled users and computers with no sign-in for InactiveDays (90 by default), or never signed in since creation, leaving out built-in, domain controller and excluded accounts.

Stale AD users and computers - who has not signed in for 90 days is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Stale AD users and computers - who has not signed in for 90 days. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows Server 2016+ (domain controller or domain member); runs as SYSTEM
NeedsPowerShell 5.1, administrator rights, ActiveDirectory module (RSAT-AD-PowerShell)
Read-onlyReads, changes nothing

What It Does

The script is read-only. It lists enabled user and computer accounts that look abandoned, one row per account, so you can review them before disabling anything. disable-stale-ad-objects uses the same selection. An account is stale when its lastLogonTimestamp is older than InactiveDays (Reason Inactive), or when it has no lastLogonTimestamp at all and was created more than InactiveDays ago (Reason NeverLoggedOn). Accounts that are already disabled are not listed.

lastLogonTimestamp is refreshed only when it is more than about 14 days old, so use an InactiveDays of 30 or more for anything you will act on. The default is 90.

Never listed, whatever the inputs: the built-in accounts (Administrator, Guest, krbtgt and DefaultAccount), anything Active Directory marks as a critical system object, domain controllers, the computer running the script, managed service accounts, trust accounts, and every account named in ExcludeAccounts. Put your service accounts in ExcludeAccounts: the script cannot tell a service account that only authenticates by Kerberos from an abandoned one.

Run it on a domain controller or a member server with the ActiveDirectory module (RSAT). If the module is missing it ends ERROR; on a computer that is not in a domain it ends SKIPPED.

Before You Run It

  • Use an InactiveDays of 30 or more. A shorter number can list accounts that signed in recently.
  • Put every service account in ExcludeAccounts before you act on the list.
  • Check the list with the client. A person on leave looks idle too.
  • Run this first, then run disable-stale-ad-objects as a dry run, before you disable anything.

Type and Risk

  • Type: Report. It collects facts into a table and never alerts. It exits 0, or 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: Under 1 minute for 1,000 accounts.
  • Example answer: "Found 14 stale account(s) idle 90+ days: 9 user(s), 5 computer(s)"
  • Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • InactiveDays: Days without a sign-in before an account is stale. Whole number, 0 to 3650. Default 90. (0 lists every account that has not signed in this moment; meant for testing, with SearchBase.)
  • SearchBase: Only look under this OU or container, as a distinguished name, e.g. "OU=Staff,DC=contoso,DC=com". Default empty: the whole domain. It must exist.
  • ExcludeAccounts: Sign-in names (SamAccountName) to leave out, separated by commas or semicolons, e.g. "svc-backup, svc-sql, PRINTSRV01". A computer may be written with or without its trailing $. * and ? are wildcards, but a wildcard needs at least 3 literal characters. Default empty.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

get-stale-ad-objects.ps1 · 906 lines · 45.8 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.