The sysadmin fixed server role gives unrestricted access to a SQL Server instance: any operation, all data, every security setting. Knowing exactly who holds it is a basic but important security review.
In many environments membership grows over time. Temporary access becomes permanent, old administrator accounts stay enabled, service accounts are granted too much, and accounts from previous teams are never removed.
This script returns every member of sysadmin with its account type, disabled status and creation details. A clean list should never contain surprises: if you do not recognise every account, you have something to investigate.
The Script
Run the following script against your SQL Server instance. It is read-only and needs VIEW ANY DEFINITION, which sysadmin and securityadmin hold already.
/*
Script Name : Get-SysadminMembers
Category : security-and-permissions
Purpose : List members of the sysadmin fixed server role.
Author : Peter Whyte (https://sqldba.blog/dba-scripts-get-sysadmin-members/)
Requires : VIEW ANY DEFINITION (sysadmin and securityadmin have it implicitly)
HealthCheck : Yes
Related : Get-ServerRoleMembers, the same check across every server role
*/
-- SAFE:ReadOnly
-- IMPACT:Low
SET NOCOUNT ON;
SELECT
sp.name AS login_name,
sp.type_desc,
sp.is_disabled,
sp.create_date,
sp.modify_date
FROM sys.server_principals sp
JOIN sys.server_role_members srm ON sp.principal_id = srm.member_principal_id
JOIN sys.server_principals sr ON srm.role_principal_id = sr.principal_id
WHERE sr.name = 'sysadmin'
ORDER BY sp.name;
Example Output
Below is the script run against a test instance. Eleven principals hold sysadmin: five SQL logins, five Windows service accounts created by the SQL Server installer, and sa. Row 4 is the one to notice. DemoDisabledAdmin carries is_disabled = 1 and still holds the role.

The status bar reads 11 rows, and that number matters more than it looks. A short result is the thing to be suspicious of, for the reason set out below.
Run it from the DBA Tools repo
git clone https://github.com/peterwhyte-lgtm/dba-tools
cd dba-tools
.\Initialize-Environment.ps1
.\run.ps1 Get-SysadminMembersAdd -ServerInstance SQLSERVER01 to run against another server. Script files: Get-SysadminMembers.sql · Get-SysadminMembers.ps1
Understanding the Results
One row per principal that is a direct member of sysadmin. Five columns, and the last two are more useful than they look.
login_namesa.WatchEvery name here should map to a person or a documented service. A name nobody can account for is the finding.type_descsys.server_principals.type_desc and not filtered, so a value you do not recognise is a real value and not a bug.Blind spotA WINDOWS_GROUP row is a group, not a person. Its members never appear here and have to be reviewed in Active Directory.is_disabled1 means the login cannot authenticate today. DemoDisabledAdmin above is the example.WatchDisabled is not removed. Re-enabling is one command and the sysadmin membership comes back with it, so review and justify rather than assuming it is harmless.create_datemodify_dateWhat This Script Does Not Tell You
Read this before using the output as evidence. The query answers one narrow question: which server principals are direct members of sysadmin.
sys.server_principals is itself permission controlled. A caller without VIEW ANY DEFINITION sees only the principals it owns and gets a shorter list rather than an error. On my test instance the full list is 11 rows. The identical query run as a plain login with no server level permission returned 1. No warning, just an instance that looks clean. Confirm the result is complete before you trust it:SELECT IS_SRVROLEMEMBER('sysadmin') AS is_sysadmin,
HAS_PERMS_BY_NAME(NULL, NULL, 'VIEW ANY DEFINITION') AS can_see_all_principals;If can_see_all_principals is 0 and you are not a sysadmin, the list is incomplete. VIEW ANY DATABASE is granted to public and does not help here, which is exactly why it is the wrong thing to check for.DOMAIN\DBA-Admins appears, that group holds sysadmin. The query shows the group and never the people inside it. To answer “who actually has sysadmin on this instance” you have to review that group in Active Directory too, and again every time its membership changes.CONTROL SERVER, ownership chaining, high privilege database roles and impersonation can add up to something close to administrative control without putting a row in this list.What to Do With the List
- Keep sysadmin small, prefer Windows groups over individual accounts, and keep application service accounts out of it.
- Disable
saif nothing uses it. It is the one sysadmin login every attacker already knows the name of. Check nothing connects assafirst (the login activity session shows who logs in), then runALTER LOGIN sa DISABLE;. - Document why each member exists, and treat every new sysadmin member as a change needing approval.
Frequently Asked Questions
Why does the script return fewer rows than I expect?
Almost always permissions. Seeing every login needs ALTER ANY LOGIN, which securityadmin holds, or VIEW ANY DEFINITION, or sysadmin (MS Docs). Without it SQL Server returns only the principals you can see instead of raising an error, so the result looks like a short, healthy list. Run the HAS_PERMS_BY_NAME check above before trusting a small number.
Why don’t I see members of Windows groups?
SQL Server stores only the Windows group as the sysadmin member. Individual users are resolved by Active Directory, so you’ll need to inspect the group’s membership outside SQL Server.
What is the sysadmin role in SQL Server?
sysadmin is a fixed server role that provides unrestricted administrative access to a SQL Server instance. Members can perform any action on the server.
Should application accounts have sysadmin access?
Generally no.
Application accounts should normally have only the permissions required for the application workload.
Should every DBA be a sysadmin?
DBAs typically require elevated access, but membership should still be controlled, documented and reviewed regularly.
Related
- Get Permissions and Role Membership, every other role and grant
- Get Login Security Audit, weak passwords and failed logins
- Get User Permissions Audit, the one-page access summary
- Get Orphaned Users, database users with no login
- Locked Out of SQL Server, regain sysadmin when nobody has it
- Login Failed for User (Error 18456), when the login cannot connect
- Security, every security script in one place
- DBA Scripts: The Complete Guide, every script on this site
Leave a Reply