SQL Server 2008 and 2008 R2 permissions query

I need  a query to list all accounts with access to 2008 and 2008 R2 SQL Servers, to list the group or usernames, account status, ie whether they are active or disabled, and a list of which accounts have been granted anmy of the server level roles, i.e. (sysadmin, serveradmin, securityadmin, processadmin, setupadmin, public etc), and ideally some indication if the account is sql login, windows login or windows group...
Who is Participating?
Vikas GargBusiness Intelligence DeveloperCommented:
Hi query to list all the accounts with enable or disable information

SELECT name AS Login_Name, type_desc AS Account_Type,is_disabled,*
FROM sys.server_principals 
WHERE TYPE IN ('U', 'S', 'G')
and name not like '%##%'
ORDER BY name, type_desc

Open in new window

pma111Author Commented:
sorry but I wanted ideally everything in one single query.
Vikas GargBusiness Intelligence DeveloperCommented:
p.name AS [Name] ,r.name,r.type_desc,r.is_disabled,r.create_date , r.modify_date,r.default_database_name,p.type_desc Account_Type
sys.server_principals r
INNER JOIN sys.server_role_members m ON r.principal_id = m.role_principal_id
INNER JOIN sys.server_principals p ON
p.principal_id = m.member_principal_id

Open in new window

Vitor MontalvãoMSSQL Senior EngineerCommented:
pma111, do you still need help on this question?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.