Following is the powershell script to script out all the Jobs in one go.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $sqlserver
$srv.JobServer.Jobs | foreach {$_.Script()}

You can copy the above code in a notepad and save it as .ps1 file in some location on server.

Next from the Object Explorer in SQL Management Studio, right click the SQL Server Name and Click on Start Powershell as shown below


This will open up powershell prompt. In the Powershell prompt you can run the above code as below

<exact path of file>scriptjobs.ps1 <<Instance Name to script>>   >     <<path of the file to redirect the script output>>

For e.g.

PS SQLSERVER:SQLPARIKS-MSFTDEFAULT> C:UserspariksDesktopscriptjobs.ps1 PARIKS-MSFTSQLR2 > C:UserspariksDesktopJob.sql

The Job.sql file will be created which will have all the Jobs scripted for that instance.

Parikshit Savjani
Premier Field Engineer

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *