Make sure SQLServerAgent job names contain no illegal filename characters and service account has write permissions to the destination folder. Edit for database servername and folder location for output files.
Const ForWriting = 2
Dim job
Dim oFSO
Dim oFSOWrite
Dim oSQLServer
Dim s
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.LoginSecure = True
oSQLServer.Connect "SERVER\INSTANCE"
For Each job in oSQLServer.JobServer.Jobs
Set oFSOWrite = oFSO.OpenTextFile("c:\Datadump\" & job.name & ".sql", ForWriting, True)
oFSOWrite.WriteLine job.Script
oFSOWrite.Close
Next
Set oFSO = Nothingo
SQLServer.Disconnect
Set oSQLServer = Nothing
No comments:
Post a Comment