< Back
Test-DbaAgentJobOwner
Post
NAME Test-DbaAgentJobOwner
SYNOPSIS
Checks SQL Agent Job owners against a login to validate which jobs do not match that owner.
SYNTAX
Test-DbaAgentJobOwner [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-Job] <System.Object[]>] [[-ExcludeJob] <System.Object[]>] [[-Login] <String>]
[-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
This function checks all SQL Agent Jobs on an instance against a SQL login to validate if that login owns those
SQL Agent Jobs or not. By default, the function checks 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.
Best practice reference: http://sqlmag.com/blog/sql-server-tip-a ... in-account
PARAMETERS
-EnableException [<Switch>]
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables
advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own
try/catch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ExcludeJob [<System.Object[]>]
Specifies the job(s) to exclude from processing. Options for this list are auto-populated from the server.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Job [<System.Object[]>]
Specifies the job(s) to process. Options for this list are auto-populated from the server. If unspecified, all
jobs will be processed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Login [<String>]
Specifies the login that you wish check for ownership. This defaults to 'sa' or the sysadmin name if sa was
renamed. This must be a valid security principal which exists on the target server.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Object[]
NOTES
Tags: Agent, Job, Owner
Author: Michael Fal (@Mike_Fal), http://mikefal.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Test-DbaAgentJobOwner -SqlInstance localhost
Returns all SQL Agent Jobs where the owner does not match 'sa'.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Test-DbaAgentJobOwner -SqlInstance localhost -ExcludeJob 'syspolicy_purge_history'
Returns SQL Agent Jobs except for the syspolicy_purge_history job
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Test-DbaAgentJobOwner -SqlInstance localhost -Login DOMAIN\\account
Returns all SQL Agent Jobs where the owner does not match DOMAIN\\account. Note
that Login must be a valid security principal that exists on the target server.
RELATED LINKS
https://dbatools.io/Test-DbaAgentJobOwner
SYNOPSIS
Checks SQL Agent Job owners against a login to validate which jobs do not match that owner.
SYNTAX
Test-DbaAgentJobOwner [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-Job] <System.Object[]>] [[-ExcludeJob] <System.Object[]>] [[-Login] <String>]
[-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
This function checks all SQL Agent Jobs on an instance against a SQL login to validate if that login owns those
SQL Agent Jobs or not. By default, the function checks 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.
Best practice reference: http://sqlmag.com/blog/sql-server-tip-a ... in-account
PARAMETERS
-EnableException [<Switch>]
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables
advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own
try/catch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ExcludeJob [<System.Object[]>]
Specifies the job(s) to exclude from processing. Options for this list are auto-populated from the server.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Job [<System.Object[]>]
Specifies the job(s) to process. Options for this list are auto-populated from the server. If unspecified, all
jobs will be processed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Login [<String>]
Specifies the login that you wish check for ownership. This defaults to 'sa' or the sysadmin name if sa was
renamed. This must be a valid security principal which exists on the target server.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Object[]
NOTES
Tags: Agent, Job, Owner
Author: Michael Fal (@Mike_Fal), http://mikefal.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Test-DbaAgentJobOwner -SqlInstance localhost
Returns all SQL Agent Jobs where the owner does not match 'sa'.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Test-DbaAgentJobOwner -SqlInstance localhost -ExcludeJob 'syspolicy_purge_history'
Returns SQL Agent Jobs except for the syspolicy_purge_history job
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Test-DbaAgentJobOwner -SqlInstance localhost -Login DOMAIN\\account
Returns all SQL Agent Jobs where the owner does not match DOMAIN\\account. Note
that Login must be a valid security principal that exists on the target server.
RELATED LINKS
https://dbatools.io/Test-DbaAgentJobOwner