Skip to content

Instantly share code, notes, and snippets.

@drconopoima
Forked from alevyinroc/Copy-ActiveJobs.ps1
Created January 21, 2026 10:32
Show Gist options
  • Select an option

  • Save drconopoima/9ff6009e8c452cffde16a627e609c0e9 to your computer and use it in GitHub Desktop.

Select an option

Save drconopoima/9ff6009e8c452cffde16a627e609c0e9 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