What It Does
The script is read-only, apart from the one baseline file it keeps. It reads the recursive membership, members of nested groups included, of the ten groups that can take over a domain: Domain Admins, Enterprise Admins, Schema Admins, Administrators, Account Operators, Backup Operators, Server Operators, Print Operators, DnsAdmins and Group Policy Creator Owners.
Groups are found by their well-known SID where Windows defines one, so a renamed or translated group is still found; DnsAdmins has no well-known SID and is found by name. Enterprise Admins and Schema Admins live in the forest root domain and are read there. A group that does not exist, such as DnsAdmins on a domain without DNS, is skipped.
It ends ALERT when AllowedMembers is set and a member of any of these groups is not on it, or when the membership of any group changed since the last run: a member was added, and the answer names who and where, or a member was removed.
The first run saves a baseline, so there are no change alerts yet. It can still alert if AllowedMembers is set and a current member is outside the list. Later runs compare with the saved baseline and try to update it, so a change normally alerts once. If saving fails, the script warns and the next run uses the older baseline. AllowedMembers keeps alerting for as long as an unapproved member stays in a group. It takes sign-in names, DOMAIN\name or SIDs, with wildcards that need at least 3 literal characters. The baseline is the file baseline.json in the test-privileged-ad-groups folder under the State folder of the MSPOutpost data folder on this computer. Delete it to start over. A run that ends ERROR does not change it.
Before You Run It
- Run it once on a quiet day to save the baseline, and check that membership by hand.
- Set AllowedMembers to the accounts that should be in these groups. Without it, only changes alert.
- Remember a change alerts once, on the run that sees it. Read the answer, not only the status.
- Schedule it on one domain controller. Each computer keeps its own baseline.
- Delete the baseline file if you want to start over, for example after a planned clean up of the groups.
- Schedule it in your RMM and alert on exit 1.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 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: "2 problem(s): jdoe added to Domain Admins; tmp-admin is not an allowed member of Administrators"
- 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.
- AllowedMembers: Accounts that may be in these groups, separated by commas or semicolons: the sign-in name (Administrator), DOMAIN\name, or a SID. * and ? are wildcards with at least 3 literal characters. Default empty: only changes alert. (Named AllowedMembers, not ApprovedMembers: PowerShell would read the runtime's -Approve as a short form of a parameter beginning with "Approve".)
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.