What It Does
The script reads every enabled user and takes the password expiry time Active Directory computes itself, which already follows the user's effective policy: the Default Domain Policy, or a fine-grained password policy that applies to the user or one of the user's groups. It lists the users whose password expires within WithinDays days, and, unless IncludeExpired is false, those already expired.
Each row has the sign-in name, display name, e-mail address, the expiry time in UTC, the days left (negative when expired), the policy name and its maximum password age. Rows are sorted soonest first, and the answer names the soonest user and how many have already expired.
It leaves out disabled users, users whose password never expires, users who must sign in with a smartcard, and users who must change their password at next sign-in, because there is nothing to warn them about. If the Default Domain Policy sets no maximum password age and no fine-grained policy applies, nobody expires and the answer says so. SearchBase limits it to one OU.
The script only reads. It sends no mail and changes nothing, so feed the rows, with ExportPath or OutputFormat Json or Csv, to whatever sends your reminders.
Before You Run It
- Run it on a domain controller or a member server with the ActiveDirectory module (RSAT) and administrator rights.
- Check that users have the mail attribute filled in, or the e-mail column will be empty.
- Pick WithinDays to match your reminder schedule. The default is 14 days.
- Use SearchBase when each client or department has its own OU.
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 users.
- Example answer: "7 user(s) with a password expiring within 14 days (1 already expired); soonest: jsmith in 2 day(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.
- WithinDays: List users whose password expires within this many days. Whole number 1 to 365. Default 14.
- IncludeExpired: true to also list users whose password has already expired. Default true.
- SearchBase: Only look at users under this OU or container, as a distinguished name. Default empty: the whole domain. It must exist.
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.