You are here

Discover How User Is Accessing SQL Instance (PowerShell and T-SQL)

When your security gets unruly, it can get time consuming to figure out how a user is accessing a SQL instance. Sometimes you may know that a user is getting access via one certain AD group but you aren't sure if any other groups are granting access. Furthermore, a user might be in a group that's nested in another group, through which they are gaining access to your SQL instance.

Using this script, you can uncover all of those scenarios.


If you don't already have it, you will need the DSQUERY command line tool installed.

For Windows 7, go to

For Windows 8 and beyond, go to

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
5 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer