Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4236704
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:40:35+00:00 2026-05-21T02:40:35+00:00

I would like to know if there is a utility out there that can

  • 0

I would like to know if there is a utility out there that can list the Server Logins on a particular server and their access.

This would be the information I get from right clicking each user -> Properties -> User Mapping
but instead of manually going through that process for each user, it just lists the information.

For example:

MyDomain\John
 - Server Roles
   - sysadmin
 - MyDatabase1
   - Roles
     db_reader
     public
 - MyDatabase2
   - Roles
     db_reader
     public
MyDomain\Steve
 - MyDatabase1
   - Roles
     db_reader
     public
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:40:35+00:00Added an answer on May 21, 2026 at 2:40 am

    I hacked up the sp_helplogins system stored procedure to return close to what you’re looking for.

    I can’t get the script to paste correctly so here is a link to the script.

    DECLARE    @LoginNamePattern     sysname    = NULL
    
    set nocount on
    
    declare
            @exec_stmt nvarchar(3550)
    
    declare
           @CountSkipPossUsers             int
          ,@Int1                           int
    
    declare
           @c10DBName                      sysname
          ,@c10DBStatus                    int
          ,@c10DBSID                       varbinary(85)
    
    declare
           @charMaxLenLoginName            varchar(11)
          ,@charMaxLenDBName               varchar(11)
          ,@charMaxLenUserName             varchar(11)
    
    declare
           @DBOptLoading                   int   --0x0020      32  "DoNotRecover"
          ,@DBOptPreRecovery               int   --0x0040      64
          ,@DBOptRecovering                int   --0x0080     128
    
          ,@DBOptSuspect                   int   --0x0100     256  ("not recovered")
          ,@DBOptOffline                   int   --0x0200     512
          ,@DBOptDBOUseOnly                int   --0x0800    2048
    
          ,@DBOptSingleUser                int   --0x1000    4096
    
    
    -------------  create work holding tables  ----------------
    -- Create temp tables before any DML to ensure dynamic
    
    
    CREATE TABLE #tb1_UA
       (
        LoginName                       sysname     collate database_default NOT Null
       ,DBName                          sysname     collate database_default NOT Null
       ,UserName                        sysname     collate database_default NOT Null
       )
    
    
    
    
    ---------------  Cursor, for DBNames  -------------------
    
    
    declare ms_crs_10_DB
       Cursor local static For
    select
                 name ,status ,sid
          from
                 master.dbo.sysdatabases
    
    
    
    OPEN ms_crs_10_DB
    
    
    -----------------  LOOP 10:  thru Databases  ------------------
    
    
    WHILE (10 = 10)
       begin    --LOOP 10: thru Databases
    
    
       FETCH
                 next
          from
                 ms_crs_10_DB
          into
                 @c10DBName
                ,@c10DBStatus
                ,@c10DBSID
    
    
       IF (@@fetch_status <> 0)
          begin
          deallocate ms_crs_10_DB
          BREAK
          end
    
    
    --------------------  Okay if we peek inside this DB now?
    
    
       IF (     @c10DBStatus & @DBOptDBOUseOnly  > 0
           AND  @c10DBSID                       <> suser_sid()
          )
          begin
          select @CountSkipPossUsers = @CountSkipPossUsers + 1
          CONTINUE
          end
    
    
       IF (@c10DBStatus & @DBOptSingleUser  > 0)
          begin
    
          select    @Int1 = count(*)
             from   sys.dm_exec_requests
             where  session_id <> @@spid
             and    database_id = db_id(@c10DBName)
    
          IF (@Int1 > 0)
             begin
             select @CountSkipPossUsers = @CountSkipPossUsers + 1
             CONTINUE
             end
          end
    
    
       IF (@c10DBStatus &
             (
               @DBOptLoading
             | @DBOptRecovering
             | @DBOptSuspect
             | @DBOptPreRecovery
             )
                   > 0
          )
          begin
          select @CountSkipPossUsers = @CountSkipPossUsers + 1
          CONTINUE
          end
    
    
       IF (@c10DBStatus &
             (
               @DBOptOffline
             )
                   > 0
          )
          begin
          --select @CountSkipPossUsers = @CountSkipPossUsers + 1
          CONTINUE
          end
    
        IF (has_dbaccess(@c10DBName) <> 1)
          begin
          raiserror(15622,-1,-1, @c10DBName)
          CONTINUE
          end
    
    
    
    ---------------------  Add the User info to holding table.
        select @exec_stmt = '
       INSERT    #tb1_UA
                (
                 DBName
                ,LoginName
                ,UserName
                )
          select
    
                 N' + quotename(@c10DBName, '''') + '
                ,l.name
                ,u2.name
             from
                 ' + quotename(@c10DBName, '[')+ '.sys.database_role_members m
                ,' + quotename(@c10DBName, '[')+ '.sys.database_principals u1
                ,' + quotename(@c10DBName, '[')+ '.sys.database_principals u2
                ,sys.server_principals l
             where
                 u1.sid = l.sid
             and m.member_principal_id = u1.principal_id
             and m.role_principal_id = u2.principal_id' +
                case 
                when @LoginNamePattern is null
                then ''
                else ' and ( l.name = N' + quotename(@LoginNamePattern , '''') + '
                    or l.name = N' + quotename(@LoginNamePattern , '''') + ')'
                end
    
       EXECUTE(@exec_stmt)
    
       end --loop 10
    
    
    ------------  Optimize UA report column display widths  -----------
    
    
    select
                 @charMaxLenLoginName   =
                      convert ( varchar
                               ,isnull ( max(datalength(LoginName)) ,9)
                              )
                ,@charMaxLenDBName      =
                      convert ( varchar
                               ,isnull ( max(datalength(DBName)) ,6)
                              )
                ,@charMaxLenUserName    =
                      convert ( varchar
                               ,isnull ( max(datalength(UserName)) ,8)
                              )
          from
                 #tb1_UA
    
    
    
    ------------  Print out the UserOrAlias report  ------------
    
    EXEC(
    '
    set nocount off
    
    
    select
              ''LoginName''    = substring (LoginName  ,1 ,'
                                           + @charMaxLenLoginName  + ')
    
             ,''DBName''       = substring (DBName     ,1 ,'
                                           + @charMaxLenDBName     + ')
    
             ,''MemberOf''     = substring (UserName   ,1 ,'
                                           + @charMaxLenUserName   + ')
    
       from
              #tb1_UA
       order by
              1 ,2 ,3
    
    
    Set nocount on
    '
    )
    
    DROP Table #tb1_UA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if there are any tools that can help me
I would like to know if there is a way where I can write
I would like to know if there is any way to add custom behaviour
I would like to know if there is some way to share a variable
I would like to know if there are general rules for creating an index
I would like to know if there is a way to disable automatic loading
I would like to know if there is an easy way to detect if
I would like to know if there is any easy way to print multiple
I would like to know if there is a simple way to parse HTML
I would like to know if there's an efficient algorithm to find the greatest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.