What It Does
The script is read-only. It lists the users of the domain this computer belongs to, one row per user. Run it on a domain controller or on 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.
Last logon is the lastLogonTimestamp attribute. Active Directory only refreshes it when it is more than about 14 days old, so it can be up to 14 days behind the real last logon. That is right for who has not signed in for months, and wrong for who signed in today. It is empty when AD has no recorded timestamp.
GroupCount counts the direct memberOf groups; the user's primary group, normally Domain Users, is not included, and nested membership is not followed. Disabled users are left out unless IncludeDisabled is true. SearchBase, a distinguished name such as OU=Staff,DC=contoso,DC=com, limits the list to one OU, and it must exist. The answer counts enabled and disabled users and how many have a password that never expires.
Before You Run It
- Run it on a domain controller, or on a member server that has the AD module.
- Do not use last logon to tell who signed in today. It can be up to 14 days behind.
- Use SearchBase for one OU when the whole domain is more than you need.
- Save the list with ExportPath as a CSV when you want to review it in a spreadsheet.
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: "Listed 152 user(s): 140 enabled, 12 disabled; 5 with a password that never expires"
- 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.
- SearchBase: Only list users under this OU or container, as a distinguished name, e.g. "OU=Staff,DC=contoso,DC=com". Default empty: the whole domain. The OU must exist.
- IncludeDisabled: Also list disabled users. true or false. Default false.
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.