Copy-DbaAgentJob -DisableOnDestination can fail to disable #8461
-
Hi, Copy-DbaAgentJob -DisableOnDestination can fail, creating the job but not disabling the job, anyway to create the job already disabled rather than copying over enabled first? I have tried working around this issue with getting jobs exporting to a SQL file and then running Invoke-SqlCmd or Invoke-DbaQuery to run the file but this cause a lot of failures handling big jobs with various USE / GO and quotation errors. For safety I need to ensure I do not have any jobs copied to the destination (secondary) server in an enabled state I can't seem to see a way to copy the job in a disabled state first (I have been instructed that I can't disable on source and copy then re-enable on source afterwards, although not even sure if that would have worked but haven't tested this given my instructions to not amend the jobs on source. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hmmm perhaps the originating command can be modified to modify the script with a replace prior to migration. But using Export-DbaScript worked for me, you can try it in the interim. |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for such a quick reply, and my apologies for not replying sooner. I did proceed down the path of scripting out the jobs individually to run these as script files to create the jobs on the secondary (destination) server, which to be honest had less errors with the job step codes using Invoke-Sqlcmd versus Invoke-DbaQuery, which threw up way more errors with syntax issues that when parsed in SQL where fine, thing GO and other commands threw it out... (but nevermind, I love the challenge so was fun to workaround! ) I came up with the following which I'm still expanding on to add error handling for missing schedules etc. but works 99% of the time, so included the PowerShell script and the two csv files it uses to allow us to dictate which is a primary and secondary server, and what job categories I want to include. Have attached my WIP code here for anyone in the future might hit a similar issue or just to see how bad my code is! Guessing that no-one else really has an issue with copy-DbaAgentJob and the disable after copy, so don't really expect it to be something that gets changed, especially in a product that is provided for free hoping people provide sponsorship |
Beta Was this translation helpful? Give feedback.
Hmmm perhaps the originating command can be modified to modify the script with a replace prior to migration. But using Export-DbaScript worked for me, you can try it in the interim.