What It Does
This script changes nothing until you set DRY_RUN=false and APPROVE=remove-mac-local-admin-members, and it refuses to demote more than 25 accounts in one run unless you raise MAX_CHANGES. Run it as a dry run and read the list first.
It reads the members of the local admin group and removes eligible members that are not in ALLOWED_ADMINS. The account itself is not deleted, not disabled and not signed out, and it keeps its files, its SecureToken and its FileVault unlock rights. It simply stops being an administrator. Before it changes anything it copies the admin group's directory record to /Library/Application Support/MSPOutpost/Backups/remove-mac-local-admin-members/.
Some accounts are always kept, whatever ALLOWED_ADMINS says: root, accounts with a user ID below 500 (system accounts), and the signed-in console user, unless DEMOTE_CONSOLE_USER is true. Taking admin rights from someone mid-session is surprising, so that is off by default.
The last administrator is never removed. A real run refuses, and changes nothing, when no kept administrator with a user ID of 500 or more would remain. ALLOWED_ADMINS entries are plain account short names, matched ignoring case, with no wildcards. An entry that is not an admin on this Mac is only a warning, so one list can serve many Macs. Admin rights that come only from a nested group are not seen.
Before You Run It
- Run it once as a dry run and read the list of who would be demoted.
- Put your management admin in ALLOWED_ADMINS. A real run needs a kept administrator with a user ID of 500 or more, which can be the protected console user.
- Warn the users. A demoted account can no longer install software or change system settings.
- If someone is still an administrator afterwards, look for a configuration profile or another tool that manages the group.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: High. It is a dry run unless you set both DRY_RUN=false and APPROVE=remove-mac-local-admin-members, and it stops before making more than 25 changes in one run unless you raise MAX_CHANGES. Run it once as a dry run and read the list first.
- What it changes: Removes accounts from the local admin group (the accounts stay as standard users).
- Restart: It never restarts the machine.
- Typical run: Under 10 seconds.
- Example answer: "Removed 2 account(s) from the admin group: jsmith, temp1; kept: root, msp-admin"
- Tested before listing on macOS 27 (Apple silicon VM) with /bin/bash 3.2, run as root, against its own test cases.
Inputs
Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.
- ALLOWED_ADMINS: Account short names that stay admin, comma-separated, e.g. "msp-admin, jsmith". Default empty: only root and the console user stay.
- DEMOTE_CONSOLE_USER: Also demote the signed-in console user when not approved. Default false.
Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.
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.