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


Checks SQL Agent Job owners against a login to validate which jobs do not match that owner.

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




To return a list of databases where the owner does not matches sa or renamed sa account.

Test-DbaJobOwner -SqlServer localhost

To return a list of 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-DbaJobOwner -SqlServer localhost -TargetLogin DOMAIN\account


SQL Server Magazine: Assign Ownership of Jobs to the SysAdmin Account


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


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

Source Code

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

Related commands