What It Does
The script finds the group by its sign-in name and lists its members, sorted by class and name. Each row has the sign-in name, the name, the object class (user, computer, group or foreignSecurityPrincipal), whether the account is enabled (for users and computers), whether the member is direct, and the distinguished name.
By default only direct members are listed, and a nested group is one row of class group. With Recursive true the members of nested groups are listed in place of the nested groups, and the Direct column shows which members were not direct, so you can see who has access only through nesting.
The answer gives the total and the number of users, computers and groups, and with Recursive on, how many came through nested groups. A group with more than about 5,000 members may be refused by Active Directory Web Services, and the script then ends in ERROR. A group that is not found also ends in ERROR. It changes nothing in the directory.
Before You Run It
- Run it on a domain controller or a member server with the ActiveDirectory module (RSAT) and administrator rights.
- Pass the group's sign-in name (sAMAccountName), not its display name.
- Use Recursive=true when the question is who actually has access, for example for Domain Admins.
- Use ExportPath to save the list as .csv or .json for an audit file.
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 30 seconds.
- Example answer: "Sales-Staff has 12 member(s): 10 user(s), 1 computer(s), 1 group(s); 3 through nested groups"
- 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.
- GroupName: The group's sign-in name (sAMAccountName). Required.
- Recursive: true to include the members of nested groups. 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.