Simon's SQL

SQL,DBA,tuning,Trouble Shooting,Performance

SQL Job Migration(powershall script)

Posted by Simon Cho on 09/18/2011


$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”

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: Logo

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

Facebook photo

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

Connecting to %s