Simon's SQL

SQL,DBA,tuning,Trouble Shooting,Performance

SQL Job Migration(powershall script)

Posted by Simon Cho on 09/18/2011

[reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”)

$server = New-Object Microsoft.SqlServer.Management.Smo.Server(“localhost”)
$scripter = New-Object Microsoft.SqlServer.Management.Smo.Scripter($server)
$jobs = $server.JobServer.get_Jobs() | Where-Object {$_.Name -notlike “sys*”}
$script = “”
foreach($job in $jobs){ $script += $job.Script() + “GO`n” }
$script >> “c:\sqljobs.sql”

http://www.sqlservercentral.com/blogs/sqlservertips/archive/2011/06/23/taking-script-of-sql-server-jobs-for-migration.aspx

Advertisements

One Response to “SQL Job Migration(powershall script)”

  1. Simon Cho said

    Set-ExecutionPolicy Unrestricted

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: