Simon's SQL

SQL,DBA,tuning,Trouble Shooting,Performance

Archive for September, 2011

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

Posted in Common | Tagged: , | 1 Comment »