Blog Archives

[SCRIPT] – Listing Database Users and Roles

I am a fan of not reinventing the wheel. What that means? Well, If I need to do something, which usually involves creating a script, I try first to do a quick search on Google and see if someone already had this idea.

Looking at the title of the article you might say: Oh, that’s easily done with dbatools, which in fact it is true. However, my use case this time was a bit different than the conventional, because I want to expose that dynamically in my Python/Django Internal tool that exposes SQL Server through API’s, so the need for a TSQL script is imminent.

The goal result that I need is:

 

User Name User Type Create Date Roles
User001 SQL_USER 2018-09-10 14:00 db_datareader
User002 WINDOWS_USER 2018-01-01 13:00 db_datareader;db_datawriter;db_ddladmin

  Read the rest of this entry