Skip to main content
KBY Technologies Logo

Audit Local Administrators Group Membership Across Windows Servers with PowerShell Remoting

Audit the local Administrators group on every Windows server with PowerShell remoting, compare it with a baseline, and undo a removal safely.

High-tech server rack in a secure data center with network cables and hardware components.

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

To audit who can administer your servers, run Get-LocalGroupMember against the built-in Administrators group on every server through Invoke-Command, save each result with the name of the server it came from, and compare the file with an approved baseline. The constraint that matters most: the account you connect with needs remoting access on each target, and by default that means being an administrator, because Microsoft documents that the default session configurations admit only members of the Administrators group.

The audit below is read-only. Removing an account from the group is a separate, reviewed step with its own rollback, covered after the checks.

#The problem: nobody owns the local Administrators group

Members of the Administrators group on a computer have Full Control permissions on it, and Microsoft’s own advice for the group is to limit the number of users in it. In practice the group collects members over time: a contractor’s account added for a migration, a helpdesk group that was meant to be temporary, a service account that needed one privileged action once.

Some entries are there by design. After installation the only member is the Administrator account. When a computer joins a domain, Domain Admins is added to the group. A baseline therefore has to separate expected entries from added ones, per server, rather than count members.

The same remoting pattern works for other estate checks. If you already look for scheduled tasks that run as privileged accounts, see finding scheduled tasks that run as privileged or stored-password accounts; the two audits answer related questions about where administrative rights sit.

#How it works: one remoting call per server

When you pass -ComputerName to Invoke-Command, PowerShell creates a temporary connection, uses it to run the script block and closes it. You can give NetBIOS names, fully qualified domain names or IP addresses in a comma-separated list. A command that names an IP address must also include -Credential, and the target must use the transport or be listed in the local WinRM TrustedHosts list. Prefer names.

Connections are made to up to 32 computers at a time by default. -ThrottleLimit changes that for the current command only. Results come back in the order the servers answer, not the order of your list, so the audit must never rely on position. Every returned object carries a PSComputerName property naming the server it ran on, and that property is the join key for everything that follows.

Loading diagram...

On the target, Get-LocalGroupMember returns LocalPrincipal objects. Their PrincipalSource property says where an account comes from: Local, , Microsoft Entra group or Microsoft Account. That column separates a local account from a domain group, so keep it in the export.

Two version limits apply. The Microsoft.PowerShell.LocalAccounts module is not available in 32-bit PowerShell on a 64-bit system, and PrincipalSource is supported only on Windows 10, 2016 and later. On earlier systems the property is blank, which is a limit of the property, not an empty group.

Contemporary computer on support between telecommunication racks and cabinets in modern data center
Photo by Brett Sayles on Pexels

#Step by step: capture, compare, then act

Start with a plain text file, servers.txt, with one server name per line. Get-Content reads a file one line at a time and returns a collection of objects, one per line, which is exactly the list -ComputerName accepts. Work from a short list first, three or four servers of different roles, before you point the script at the estate.

  1. Capture the membership of every server in one command.
    1$servers = Get-Content -Path .\servers.txt
    2
    3$rows = Invoke-Command -ComputerName $servers -ErrorVariable remoteErrors -ScriptBlock {
    4    Get-LocalGroupMember -SID 'S-1-5-32-544' |
    5        Select-Object Name, PrincipalSource
    6}
  2. Save the result, with the server name, to a dated file.
    1$rows | Select-Object PSComputerName, Name, PrincipalSource |
    2    Export-Csv -Path .\local-admins-2026-12-01.csv -NoTypeInformation
  3. Compare it with the approved baseline.
    1$baseline = Import-Csv -Path .\local-admins-baseline.csv
    2$current  = Import-Csv -Path .\local-admins-2026-12-01.csv
    3
    4Compare-Object -ReferenceObject $baseline -DifferenceObject $current -Property PSComputerName, Name

Following along? Tap a step’s number to tick it off.

The script selects the group by its SID, S-1-5-32-544, which is the documented SID of the built-in Administrators group. The cmdlet’s own example uses the name "Administrators"; the SID form avoids any dependence on the group’s display name. -ErrorVariable stores the error records the command emits in $remoteErrors, in addition to the usual $Error list, so the servers that did not answer stay on record.

In the comparison, Compare-Object treats the first set as the reference and the second as the difference. A SideIndicator of => means the account appears only in today’s capture, which is the one to investigate. A <= means it was in the baseline but is gone. The first baseline is simply the first capture, after someone responsible has read it line by line and approved it.

Only when a member is confirmed as not needed should you remove it, one server and one account at a time. Run the command with -WhatIf first. That parameter shows what would happen and does not run the cmdlet.

1Invoke-Command -ComputerName SERVER01 -ScriptBlock {
2    Remove-LocalGroupMember -SID 'S-1-5-32-544' -Member 'CONTOSO\jsmith' -WhatIf
3}

Remove the -WhatIf only when the preview names exactly the account you approved, written as the capture file records it. If no preview text appears over the remoting connection, stop and run the preview in an interactive session on that server instead. -Member accepts a name, a SID or a LocalPrincipal object.

#Check it worked: every server accounted for

A clean comparison proves little if half the servers never answered. Treat the audit as complete only when every name in servers.txt appears either in the results or in the errors. Group the output by PSComputerName, subtract those names from the list, and read what is left against $remoteErrors. Any server in neither place is a silent gap and needs a rerun.

Then check the content. Each server should list at least the accounts you expect from the baseline, and the PrincipalSource column should be filled in on servers that support it. A blank column is expected on a server older than Windows Server 2016. On Server 2016 or later it deserves a closer look before you trust the rest of that server’s rows.

For a removal, verify with a fresh read of the same server rather than trusting the absence of an error:

1Invoke-Command -ComputerName SERVER01 -ScriptBlock {
2    Get-LocalGroupMember -SID 'S-1-5-32-544'
3}

The account you removed must be gone, and every other member must still be present. Save the output with the change record.

A woman deeply engrossed in programming on a laptop at night in a data center.
Photo by Christina Morillo on Pexels

#What goes wrong

Most audit failures are access failures, and they are quiet unless you look for them. The table lists the ones you are most likely to meet.

Common audit failures and the usual cause
What you seeLikely causeWhat to do
A server is missing from the resultsWinRM is not running or reachable, or the account is not allowed to connectRead its entry in $remoteErrors; check the service with Test-WSMan -ComputerName SERVER01
The connection fails when you use IP addressesIP addresses need -Credential plus HTTPS or a TrustedHosts entryUse the server’s name, or fix the transport rather than widening TrustedHosts
The module or cmdlet is not foundThe session is 32-bit PowerShell on a 64-bit systemRun the audit from a 64-bit session
PrincipalSource is blankThe server runs a Windows version before 10 or Server 2016Judge those servers by account name and plan their replacement
Results look out of orderOutput arrives in the order servers replyGroup or sort by PSComputerName
The local machine fails but others workRemoting to the local computer needs an elevated sessionStart PowerShell with Run as administrator

Errors in a remote command do not stop the run. Errors that would be terminating locally are treated as non-terminating, so one failing computer does not close the command on all the others. That is why the audit can finish with a partial result, and why you must reconcile the list.

Test-WSMan sends an identification request and tells you whether the WinRM service is running on the target. Whether your account may connect is a separate question, answered by the group membership described below.

Remoting itself has requirements on both sides. Microsoft lists Windows PowerShell 3.0 or higher, the .NET Framework 4 or higher and WinRM 3.0 or higher, and recommends WMF 5.1 for full support. Check each server against that list; one that does not meet it belongs on your register of exceptions until it is updated.

#Least privilege for the audit account

The audit looks harmless, but it needs a powerful account. To run remote commands, the account must belong to the Administrators or Remote Management Users group on the target, and the default session configurations, Microsoft.PowerShell and Microsoft.PowerShell32, allow only members of the Administrators group. So with the default endpoints, the account that reads the group is, on every server it audits, a member of the group it reads, with Full Control.

Plan around that. Use a dedicated account, not a person’s daily account. Run the audit from one hardened management host. Do not put the password in the script; the approach in storing scheduled-task passwords with SecretManagement and SecretStore keeps it out of the file. Microsoft documents that other session configurations can be created with different access rules, so a narrower endpoint is possible, but it is a design project of its own and not covered here.

Treat the output as sensitive. The CSV maps privileged accounts to the servers they control, which is precisely what an attacker looking for a path would want. Store it where only the team that reviews it can read it, and keep the baseline under change control, so an approved entry is a recorded decision and not an edit made to silence a difference.

Two further cautions, both KBY recommendations and not Microsoft guidance. Never remove the account you are connecting with before you have confirmed another working route to the server, such as a second administrator or a console path. And do not remove a default entry, such as Domain Admins on a domain-joined server, without a plan, because it is there by design.

#Rollback: undoing a removal

Removing a member is reversible while the account still exists, because Add-LocalGroupMember adds users or groups back. Before any removal, keep the capture file from the same day, which names the member and the server, and write the approval beside it. To undo, run this on the same server:

1Invoke-Command -ComputerName SERVER01 -ScriptBlock {
2    Add-LocalGroupMember -SID 'S-1-5-32-544' -Member 'CONTOSO\jsmith' -WhatIf
3}

Check the preview, drop -WhatIf to apply it, then read the group again as you did after the removal. Both cmdlets accept a name, a SID or a LocalPrincipal object for -Member.

If many servers are affected, stop. Do not script a bulk rollback until you know why a bulk removal happened. Compare the capture from before with a fresh one to see what changed, restore entries one server at a time, and run the comparison again. When the difference list is empty, the change is fully reversed.

The audit then becomes routine: capture on a schedule, compare against the baseline, review only the differences, and keep each dated CSV as evidence. If your estate also depends on certificates reachable over the same remoting channel, finding expiring certificates on Windows servers reuses the same server list and the same checks for unanswered hosts.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Found this useful? Follow KBY for more like it.

Reader Interaction

Comments

Add a thoughtful note on Audit Local Administrators Group Membership Across Windows Servers with PowerShell Remoting. Comments are checked for spam and held for moderation before appearing.

Loading comments...

More from KBY that goes with this article.

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Engineering insights, direct to you.

Receive the latest Systems Engineering tutorials, production guides, Engineering Labs and operational best practices.