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-DbaAgentJob

New-DbaAgentJob makes it possible to create a job in the SQL Server Agent. It returns an array of the job(s) created

Screenshots

dbatools-New-DbaAgentJob

Examples

Creates a job with the name “Job1” and a small description.

New-DbaAgentJob -SqlInstance sql1 -Job ‘Job One’ -Description ‘Just another job’

Creates the job but sets it to disabled.

New-DbaAgentJob -SqlInstance sql1 -Job ‘Job One’ -Disabled

Creates the job and sets the notification to write to the Windows Application event log on success.

New-DbaAgentJob -SqlInstance sql1 -Job ‘Job One’ -EventLogLevel OnSuccess

Creates the job and sets the notification to send an e-mail to the e-mail operator.

New-DbaAgentJob -SqlInstance SSTAD-PC -Job ‘Job One’ -EmailLevel OnFailure -EmailOperator dba

Doesn’t create the job but shows what would happen.

New-DbaAgentJob -SqlInstance sql1 -Job ‘Job One’ -Description ‘Just another job’ -Whatif

Creates a job with the name “Job One” on multiple servers.

New-DbaAgentJob -SqlInstance sql1, sql2, sql3 -Job ‘Job One’

Creates a job with the name “Job One” on multiple servers using the pipeline.

“sql1”, “sql2”, “sql3” | New-DbaAgentJob -Job ‘Job One’

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-DbaAgentJob -Detailed for more information on this function.

Source Code

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

Related commands