Use WIndows Power Shell to Script SQL Jobs from one instance to another

  1. Open Powershell
  2. Execute Invoke-Sqlcmd
  3. Execute $output = "d:\ScheduledJobs.sql"
  4. Execute Remove-Item $output
  5. Execute Set-Location SQLSERVER:\SQL\localhost\DEFAULT\JobServer\Jobs
  6. Execute # loop through jobs appending output
  7. Lastly Execute dir | %{$_.script() + "`n`nGO`n`n" | out-file -append $output}

Do the above one line at a time then take the output ScheduledJobs.sql go to the new server and open Management Studio and run the script.

Vince Stefanetti

Leave a Reply

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