PowerShell Genie

Report local Administrators members

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-LocalGroupMember resolves the group membership and returns each principal with two useful qualifiers.

The script

1PS> Get-LocalGroupMember -Group Administrators | Select-Object Name,ObjectClass,PrincipalSource

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Name ObjectClass PrincipalSource
    2 ---- ----------- ---------------
    3 CONTOSO\Server Admins Group ActiveDirectory
    4 SRV01\LocalAdmin User Local
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-LocalGroupMember -Group Administrators | Select-Object Name,ObjectClass,PrincipalSource
    1. Stage 1Get-LocalGroupMember-Group
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-LocalGroupMember resolves the group membership and returns each principal with two useful qualifiers. ObjectClass says whether the entry is a user or a nested group, and PrincipalSource separates a local account from a domain one. Select-Object keeps those columns next to the resolved name.

      Adapting it

      Point -Group at Remote Desktop Users or Backup Operators to cover the other groups that grant meaningful access on a member server.

      Requirements

      Elevation on most builds.

      If the result is unexpected

      The enumeration fails with "Failed to compare two elements in the array" or a message about a principal that could not be resolved, and no membership list comes back at all.

      The cmdlet resolves every member SID to a name, and a SID left behind by a deleted domain account or belonging to an unreachable trusted domain cannot be resolved. Its internal sorting then fails on that entry and aborts the whole call rather than returning the members it did resolve. This is known behavior in the LocalAccounts module rather than a permissions issue.

      1. Confirm the session is elevated, since an unelevated attempt fails with a different and much clearer access message.
      2. Fall back to net localgroup Administrators, which prints raw entries including the ones that will not resolve.
      3. Read the membership through the WinNT ADSI provider when the cmdlet keeps failing.
      4. Remove orphaned entries with net localgroup Administrators /delete using the SID string itself.
      5. Check whether a trusted domain is unreachable, because that produces the same symptom with no orphaned entry involved.

      Validate the result

      The cmdlet returns the full membership with every entry resolving to a name, and the count matches what net localgroup reports.

      Keep the check reliable

      Remove accounts from local groups during offboarding rather than only deleting the directory object, since that is what leaves the orphaned SID behind.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideReport local Administrators members

      Get-LocalGroupMember resolves the group membership and returns each principal with two useful qualifiers.