SQL: Determining the Windows Groups for a SQL Server Login

SQL: Determining the Windows Groups for a SQL Server Login

I saw a question on a SQL Server mailing list about how to determine the Windows groups for a given SQL Server login.

That’s actually easy for a sysadmin login, as they have IMPERSONATE permission for other logins/users.

Here is an example procedure:

USE tempdb;
GO

CREATE OR ALTER PROCEDURE dbo.GetGroupsForALogin
@LoginName sysname
AS
BEGIN
    EXECUTE AS Login = @LoginName;

    SELECT [name] AS GroupName,
           usage AS Usage
    FROM sys.login_token 
    WHERE [type] = N'WINDOWS GROUP';
END;
GO

When I executed this on one of my SQL Server 2025 systems this way:

EXEC dbo.GetGroupsForALogin N'GREG7680V2\Greg';

It returned the following:

image

Note that the Usage column could also return DENY ONLY or AUTHENTICATOR.

2026-06-03