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


Test-DbaDatabaseOwner

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.

Screenshots

Test-DbaDatabaseOwner

Test-DbaDatabaseOwner12

Examples

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’

References

Dan Guzman’s Database Owner Troubles.

Author

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

Get-Help

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