Back to Resources
Level
Script
Security
This script addresses the challenge of managing local administrator privileges in Windows environments, where it can be difficult to discern which accounts hold elevated rights and whether those accounts remain enabled. By providing a clear overview of current local admins, it empowers IT professionals and MSPs to comply with security best practices and avert potential unauthorized access.
The script examines the local Administrators group on a Windows system, filtering out only those accounts that are actively enabled. It then consolidates these account names into a comma-separated list, ensuring that you have a concise snapshot of all active admins. By returning an easy-to-read output, it streamlines privilege oversight and helps administrators rapidly identify any unexpected or unnecessary elevated privileges.
Because Level runs scripts with system-level permissions, no additional elevation is required. Once executed, you’ll have a swift and reliable means of auditing local administrative rights without complicated workarounds or manual checks.
<#
This resource is provided as a convenience for Level users. We cannot
guarantee it will work in all environments. Please test before deploying
to your production environment. We welcome contributions to our community
library
Level Library
https://level.io/library/script-windows-get-local-admins
#>
# Get all local admins that are enabled
$admins = Get-LocalGroupMember -Group "Administrators" |
Where-Object { $_.ObjectClass -eq 'User' -and (Get-LocalUser $_.SID).Enabled -eq $true } |
Select-Object -ExpandProperty Name
# Extract just the username by splitting on '\' and taking the last part
$admins = $admins | ForEach-Object { ($_ -split '\\')[-1] }
# Join the usernames into a single string separated by commas
$detectedAdmins = $admins -join ","
# Output for verification
Write-Output $detectedAdmins
Windows - Get Local Admins
This PowerShell script retrieves a list of all enabled local administrator accounts on a Windows system, processes them to extract just the usernames (removing domain prefixes if present), and outputs them as a comma-separated string. The script is part of the Level.io community library and includes built-in filtering to only show active administrator accounts, making it useful for auditing and monitoring administrative access on Windows machines.
PowerShell
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.