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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vikas GargAssociate Principal EngineerCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pma111Author Commented:
sorry but I wanted ideally everything in one single query.
Vikas GargAssociate Principal EngineerCommented:
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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.