Skip to content
Menu

Too Many Local Admins - Remove the Unapproved Ones

Removes local administrators who are not in AllowedMembers, keeping built-in, system and LAPS accounts, and saves the member list first. Needs DryRun=false and Approve.

Too many local admins - remove the unapproved ones is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Too many local admins - remove the unapproved ones. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights
Changes thingsChanges what it runs on

What It Does

This script changes nothing until you set DryRun=false and Approve=remove-local-admin-members. Before that it lists who would be removed. It refuses to remove more members than MaxChanges, 25 by default, in one run.

It reads the members of the built-in Administrators group by its SID and removes each member that is not in AllowedMembers. Only the group membership changes: the account is not deleted, disabled or signed out, and keeps working as a standard user. Before removing anyone it saves the full member list, with name, type, source and SID, as a CSV in the MSPOutpost backup folder.

Always kept, whatever AllowedMembers says: the built-in Administrator, Domain Admins, the account running the script, every system principal, every account a Windows service logs on as, and the account Windows LAPS or legacy LAPS manages. A real run also refuses, changing nothing, when no enabled approved account, built-in Administrator, Domain Admins entry or LAPS administrator would remain. A domain controller is skipped.

An approved entry matches the full name, the short name or a SID, ignoring case, and * and ? work as wildcards with at least 3 literal characters. A person who is an administrator only through a domain or Entra group is not visible here, so approve the group. Entra roles Windows adds on an Entra-joined PC are S-1-12-1 members, so approve them by SID.

Before You Run It

  • Run it as a dry run first and read who would be removed. Check every name for typos.
  • Approve any domain or Entra group your technicians use, and Entra roles by SID, or they are removed too.
  • Check that you will still have working administration access after the proposed removals.
  • Know that the member list is saved first, so any member can be added back.

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 DryRun=false and Approve=remove-local-admin-members, and it stops before making more than 25 changes in one run unless you raise MaxChanges. Run it once as a dry run and read the list first.
  • What it changes: Removes members from the local Administrators group; saves the member list first.
  • Restart: It never restarts the machine.
  • Typical run: Under 15 seconds.
  • Example answer: "Removed 2 of 2 unapproved local administrator(s): PC01\jsmith, PC01\temp-admin"
  • Tested before listing on Windows 11 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: Members allowed to stay local administrators (named AllowedMembers, not ApprovedMembers: PowerShell would read the runtime's -Approve as a short form of a parameter beginning with "Approve"), separated by commas or semicolons, e.g. "outpost, CONTOSO\Desk Techs, S-1-12-1-111-222-333-444". Default empty: only the always-kept members stay.

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.

The Script

remove-local-admin-members.ps1 · 986 lines · 50.8 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.