< Back
Set-DbaAgentJobStep
Post
NAME Set-DbaAgentJobStep
SYNOPSIS
Set-DbaAgentJobStep updates a job step.
SYNTAX
Set-DbaAgentJobStep [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-Job] <System.Object[]>] [[-StepName] <String>] [[-NewName] <String>] [[-Subsystem] <String>]
[[-SubsystemServer] <String>] [[-Command] <String>] [[-CmdExecSuccessCode] <Int>] [[-OnSuccessAction] <String>]
[[-OnSuccessStepId] <Int>] [[-OnFailAction] <String>] [[-OnFailStepId] <Int>] [[-Database] <String>]
[[-DatabaseUser] <String>] [[-RetryAttempts] <Int>] [[-RetryInterval] <Int>] [[-OutputFileName] <String>] [[-Flag]
<System.String[]>] [[-ProxyName] <String>] [[-InputObject] <Microsoft.SqlServer.Management.Smo.Agent.JobStep[]>]
[-EnableException <Switch>] [-Force <Switch>] [<CommonParameters>]
DESCRIPTION
Set-DbaAgentJobStep updates a job step in the SQL Server Agent with parameters supplied.
PARAMETERS
-CmdExecSuccessCode [<Int>]
The value returned by a CmdExec subsystem command to indicate that command executed successfully.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Command [<String>]
The commands to be executed by SQLServerAgent service through subsystem.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<String>]
The name of the database in which to execute a Transact-SQL step. The default is 'master'.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-DatabaseUser [<String>]
The name of the user account to use when executing a Transact-SQL step. The default is 'sa'.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-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
-Flag [<System.String[]>]
Sets the flag(s) for the job step.
Flag Description
----------------------------------------------------------------------------
AppendAllCmdExecOutputToJobHistory Job history, including command output, is appended to the job history
file.
AppendToJobHistory Job history is appended to the job history file.
AppendToLogFile Job history is appended to the SQL Server log file.
AppendToTableLog Job history is appended to a log table.
LogToTableWithOverwrite Job history is written to a log table, overwriting previous contents.
None Job history is not appended to a file.
ProvideStopProcessEvent Job processing is stopped.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Force [<Switch>]
The force parameter will ignore some errors in the parameters and assume defaults.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<Microsoft.SqlServer.Management.Smo.Agent.JobStep[]>]
Enables piping job objects
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Job [<System.Object[]>]
The name of the job. Can be null if the the job id is being used.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NewName [<String>]
The new name for the step in case it needs to be renamed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnFailAction [<String>]
The action to perform if the step fails.
Allowed values "QuitWithSuccess" (default), "QuitWithFailure", "GoToNextStep", "GoToStep".
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnFailStepId [<Int>]
The ID of the step in this job to execute if the step fails and OnFailAction is "GoToNextStep".
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnSuccessAction [<String>]
The action to perform if the step succeeds.
Allowed values "QuitWithSuccess" (default), "QuitWithFailure", "GoToNextStep", "GoToStep".
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnSuccessStepId [<Int>]
The ID of the step in this job to execute if the step succeeds and OnSuccessAction is "GoToNextStep".
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OutputFileName [<String>]
The name of the file in which the output of this step is saved.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ProxyName [<String>]
The name of the proxy that the job step runs as.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-RetryAttempts [<Int>]
The number of retry attempts to use if this step fails. The default is 0.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-RetryInterval [<Int>]
The amount of time in minutes between retry attempts. The default is 0.
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. You must have sysadmin access and server version must be SQL
Server version 2000 or greater.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-StepName [<String>]
The name of the step.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Subsystem [<String>]
The subsystem used by the SQL Server Agent service to execute command.
Allowed values 'ActiveScripting','AnalysisCommand','AnalysisQuery','CmdExec','Distribution','LogReader','Merge'
,'PowerShell','QueueReader','Snapshot','Ssis','TransactSql'
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SubsystemServer [<String>]
The subsystems AnalysisScripting, AnalysisCommand, AnalysisQuery ned the server property to be able to apply
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
NOTES
Tags: Agent, Job, JobStep
Author: Sander Stad (@sqlstad), sqlstad.nl
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -NewName Step2
Changes the name of the step in "Job1" with the name Step1 to Step2
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -Database msdb
Changes the database of the step in "Job1" with the name Step1 to msdb
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1 -Job Job1, Job2 -StepName Step1 -Database msdb
Changes job steps in multiple jobs with the name Step1 to msdb
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1, Job2 -StepName Step1 -Database msdb
Changes job steps in multiple jobs on multiple servers with the name Step1 to msdb
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1 -StepName Step1 -Database msdb
Changes the database of the step in "Job1" with the name Step1 to msdb for multiple servers
-------------------------- EXAMPLE 6 --------------------------
PS C:\\>sql1, sql2, sql3 | Set-DbaAgentJobStep -Job Job1 -StepName Step1 -Database msdb
Changes the database of the step in "Job1" with the name Step1 to msdb for multiple servers using pipeline
RELATED LINKS
https://dbatools.io/Set-DbaAgentJobStep
SYNOPSIS
Set-DbaAgentJobStep updates a job step.
SYNTAX
Set-DbaAgentJobStep [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-Job] <System.Object[]>] [[-StepName] <String>] [[-NewName] <String>] [[-Subsystem] <String>]
[[-SubsystemServer] <String>] [[-Command] <String>] [[-CmdExecSuccessCode] <Int>] [[-OnSuccessAction] <String>]
[[-OnSuccessStepId] <Int>] [[-OnFailAction] <String>] [[-OnFailStepId] <Int>] [[-Database] <String>]
[[-DatabaseUser] <String>] [[-RetryAttempts] <Int>] [[-RetryInterval] <Int>] [[-OutputFileName] <String>] [[-Flag]
<System.String[]>] [[-ProxyName] <String>] [[-InputObject] <Microsoft.SqlServer.Management.Smo.Agent.JobStep[]>]
[-EnableException <Switch>] [-Force <Switch>] [<CommonParameters>]
DESCRIPTION
Set-DbaAgentJobStep updates a job step in the SQL Server Agent with parameters supplied.
PARAMETERS
-CmdExecSuccessCode [<Int>]
The value returned by a CmdExec subsystem command to indicate that command executed successfully.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Command [<String>]
The commands to be executed by SQLServerAgent service through subsystem.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<String>]
The name of the database in which to execute a Transact-SQL step. The default is 'master'.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-DatabaseUser [<String>]
The name of the user account to use when executing a Transact-SQL step. The default is 'sa'.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-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
-Flag [<System.String[]>]
Sets the flag(s) for the job step.
Flag Description
----------------------------------------------------------------------------
AppendAllCmdExecOutputToJobHistory Job history, including command output, is appended to the job history
file.
AppendToJobHistory Job history is appended to the job history file.
AppendToLogFile Job history is appended to the SQL Server log file.
AppendToTableLog Job history is appended to a log table.
LogToTableWithOverwrite Job history is written to a log table, overwriting previous contents.
None Job history is not appended to a file.
ProvideStopProcessEvent Job processing is stopped.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Force [<Switch>]
The force parameter will ignore some errors in the parameters and assume defaults.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<Microsoft.SqlServer.Management.Smo.Agent.JobStep[]>]
Enables piping job objects
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Job [<System.Object[]>]
The name of the job. Can be null if the the job id is being used.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NewName [<String>]
The new name for the step in case it needs to be renamed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnFailAction [<String>]
The action to perform if the step fails.
Allowed values "QuitWithSuccess" (default), "QuitWithFailure", "GoToNextStep", "GoToStep".
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnFailStepId [<Int>]
The ID of the step in this job to execute if the step fails and OnFailAction is "GoToNextStep".
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnSuccessAction [<String>]
The action to perform if the step succeeds.
Allowed values "QuitWithSuccess" (default), "QuitWithFailure", "GoToNextStep", "GoToStep".
The text value van either be lowercase, uppercase or something in between as long as the text is correct.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OnSuccessStepId [<Int>]
The ID of the step in this job to execute if the step succeeds and OnSuccessAction is "GoToNextStep".
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OutputFileName [<String>]
The name of the file in which the output of this step is saved.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ProxyName [<String>]
The name of the proxy that the job step runs as.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-RetryAttempts [<Int>]
The number of retry attempts to use if this step fails. The default is 0.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-RetryInterval [<Int>]
The amount of time in minutes between retry attempts. The default is 0.
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. You must have sysadmin access and server version must be SQL
Server version 2000 or greater.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-StepName [<String>]
The name of the step.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Subsystem [<String>]
The subsystem used by the SQL Server Agent service to execute command.
Allowed values 'ActiveScripting','AnalysisCommand','AnalysisQuery','CmdExec','Distribution','LogReader','Merge'
,'PowerShell','QueueReader','Snapshot','Ssis','TransactSql'
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SubsystemServer [<String>]
The subsystems AnalysisScripting, AnalysisCommand, AnalysisQuery ned the server property to be able to apply
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
NOTES
Tags: Agent, Job, JobStep
Author: Sander Stad (@sqlstad), sqlstad.nl
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -NewName Step2
Changes the name of the step in "Job1" with the name Step1 to Step2
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -Database msdb
Changes the database of the step in "Job1" with the name Step1 to msdb
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1 -Job Job1, Job2 -StepName Step1 -Database msdb
Changes job steps in multiple jobs with the name Step1 to msdb
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1, Job2 -StepName Step1 -Database msdb
Changes job steps in multiple jobs on multiple servers with the name Step1 to msdb
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Set-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1 -StepName Step1 -Database msdb
Changes the database of the step in "Job1" with the name Step1 to msdb for multiple servers
-------------------------- EXAMPLE 6 --------------------------
PS C:\\>sql1, sql2, sql3 | Set-DbaAgentJobStep -Job Job1 -StepName Step1 -Database msdb
Changes the database of the step in "Job1" with the name Step1 to msdb for multiple servers using pipeline
RELATED LINKS
https://dbatools.io/Set-DbaAgentJobStep