dbatools is a free PowerShell module with over 180 SQL Server administration, best practice and migration commands included.


Watch-SqlDbLogin uses SQL Server process enumeration to track logins in a SQL Server table. This is helpful when you need to migrate a SQL Server, and update connection strings, but have inadequate documentation on which servers/applications are logging into your SQL instance. See the Script Center page for more information.

Running this script every 90 seconds for a few weeks should give you a sufficient idea about database and login usage.

The data in the SQL table looks like this:

enter image description here

Use the following code to setup the required SQL table


From PowerShell, execute Get-Help Watch-SqlDbLogin -Detailed for more information on this function.

Source Code

Want to see the source code? View Watch-SqlDbLogin.ps1 on GitHub

Related commands