Skip to content

Instantly share code, notes, and snippets.

@alevyinroc
Created December 25, 2018 19:48
Show Gist options
  • Select an option

  • Save alevyinroc/780e8484669a2d36ed1095dfd06588e2 to your computer and use it in GitHub Desktop.

Select an option

Save alevyinroc/780e8484669a2d36ed1095dfd06588e2 to your computer and use it in GitHub Desktop.
# Export current jobs to scripts
Get-DbaAgentJob -SqlInstance $OldInstance | Where-Object {-not $_.isenabled} | ForEach-Object {Export-DbaScript $_ -Path (Join-Path -Path s:\Temp\2016Migration\DisabledJobs -Childpath "$($_.name.replace('\','$')).sql")};
Get-DbaAgentJob -SqlInstance $OldInstance | Where-Object {$_.isenabled} | ForEach-Object {Export-DbaScript $_ -Path (Join-Path -Path s:\Temp\2016Migration\EnabledJobs -Childpath "$($_.name.replace('\','$')).sql")};
# Get only the enabled job
$JobsToCopy = Get-DbaAgentJob -SqlInstance $OldInstance -ExcludeDisabledJobs;
# Copy the Operator(s) from the existing server
Copy-DbaAgentOperator -Source $oldinstance -Destination $newinstance;
# Copy only the enabled jobs and disable on the new server
Copy-DbaAgentJob -Source $OldInstance -Destination $NewInstance -Job $JobsToCopy.Name -verbose -DisableOnDestination;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment