Using TSQL How to Script All SQL Server Agent Jobs into One File

LauraC 21 Reputation points
2022-10-07T00:31:29.01+00:00

I am trying to find TSQL that will script all the SQL Server Agent Jobs into one File. I haven't found anything yet. Can someone point me to an URL that I can look into?

We are uninstalling SQL Server Standard and installing SQL Server Developer, thus, I have to script out the jobs into a file on a directory in a server before the uninstall and after installing SQL Server Developer then I can execute the file.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
0 comments No comments
{count} votes

9 answers

Sort by: Most helpful
  1. LauraC 21 Reputation points
    2022-10-11T01:22:28.843+00:00

    I don't think I can use https://docs.dbatools.io/Export-DbaScript. I cannot get it to work. Still looking for TSQL code that will work.

    0 comments No comments

  2. Olaf Helper 47,581 Reputation points
    2022-10-11T10:00:36.83+00:00

    The term 'Get-DbaAgentJob' is not recognized as the name of a cmdlet,

    You have to install/import the CmdLet first, see https://dbatools.io/download/

    0 comments No comments

  3. LauraC 21 Reputation points
    2022-10-13T01:32:52.777+00:00

    This is what I have typed in..........................................

    PS C:\Windows\system32> Install-Module dbatools

    PS C:\Windows\system32> Get-DbaAgentJob -SqlInstance DEV01 | Export-DbaScript -FilePath C:\Users\UserNameHere\export.sql -Append
    WARNING: [21:15:50][Get-DbaAgentJob] Failure | The network path was not found

    PS C:\Windows\system32> Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

    PS C:\Windows\system32> Install-Module dbatools

    PS C:\Windows\system32> Get-DbaAgentJob -SqlInstance DEV01 | Export-DbaScript -FilePath C:\Users\UserNameHere\export.sql -Append
    WARNING: [21:23:14][Get-DbaAgentJob] Failure | The network path was not found

    PS C:\Windows\system32>

    What does this error "WARNING: [21:23:14][Get-DbaAgentJob] Failure | The network path was not found" mean?
    What am I doing wrong?

    0 comments No comments

  4. LauraC 21 Reputation points
    2022-10-18T03:11:51.627+00:00

    I was finally able to get dbtools to work. But I am being told that we cannot use it because it is a 3rd Party Tool. Is that true? Is it considered a 3rd Party Tool?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.