dbatools is a free PowerShell module with over 200 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


New-DbaAgentJobStep

New-DbaAgentJobStep creates a new job in the SQL Server Agent for a specific job.

Screenshots

dbatools - New-DbaAgentJobStep

Examples

Create a step in “Job1” with the name Step1 with the default subsystem TransactSql.

New-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1

Create a step in “Job1” with the name Step1 where the database will the msdb.

New-DbaAgentJobStep -SqlInstance sql1 -Job Job1 -StepName Step1 -Database msdb

Create a step in “Job1” with the name Step1 where the database will the “msdb” for multiple servers.

New-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1 -StepName Step1 -Database msdb

Create a step in “Job1” with the name Step1 where the database will the “msdb” for multiple servers for multiple jobs

New-DbaAgentJobStep -SqlInstance sql1, sql2, sql3 -Job Job1, Job2, ‘Job Three’ -StepName Step1 -Database msdb

Create a step in “Job1” with the name Step1 where the database will the “msdb” for multiple servers using pipeline

sql1, sql2, sql3 | New-DbaAgentJobStep -Job Job1 -StepName Step1 -Database msdb

Author

This command was created by Sander Stad. You can find Sander on Twitter and his blog.

Get-Help

From PowerShell, execute Get-Help New-DbaAgentJobStep -Detailed for more information on this function.

Source Code

Want to see the source code? View New-DbaAgentJobStep.ps1 on GitHub
 

Related commands