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

Please note that documentation and command names may be out of date while we work furiously towards 1.0


This function will check all databases on an instance against a SQL login to validate if that login owns those databases or not. By default, the function will check against ‘sa’ (or renamed sa account) for ownership, but the user can pass a specific login if they use something else. Only databases that do not match this ownership will be displayed, but if the -Detailed switch is set all databases will be shown.





Return all databases where the owner does not match ‘sa’.

Test-DbaDatabaseOwner -SqlServer localhost

Return all databases where the owner does not match ‘DOMAIN\account’. Note that TargetLogin must be a valid security principal that exists on the target server.

Test-DbaDatabaseOwner -SqlServer localhost -TargetLogin ‘DOMAIN\account’


Dan Guzman’s Database Owner Troubles.


This command was created by Mike Fal. You can find Mike on Twitter, mikefal.net and LinkedIn.


From PowerShell, execute Get-Help Test-DbaDatabaseOwner -Detailed for more information on this function.

Source Code

Want to see the source code? View Test-DbaDatabaseOwner.ps1 on GitHub

Related commands