question

Devesh_Srivastava avatar image
Devesh_Srivastava asked

Need help to script out multiple SQL Jobs listed in an XMl file

Hello Everyone, This is kind of urgent for me and I need your help in this regard. I need to script out SQL jobs which are listed in an XML file for a SQL instance. I did go through the articles and forums for the script and found some links for me to atleast get started but I am totally new SQL Server SMO programming and I dont know how and what changes to make in the script listed in the link below: http://www.johnsansom.com/script-sql-server-agent-jobs-using-powershell/ I don't need a solution through SSMS since the name of jobs could be different everytime in the XML file. Please help me guys!!! Thanks Devesh
smo
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
This site functions according to votes. For all helpful answers below, show this by clicking on the thumbs up next to those answers. If any one answer lead to a solution, indicate this by clicking on the check mark next to that answer.
0 Likes 0 ·
David Wimbush avatar image
David Wimbush answered
Does it have to be an XML file? I'm sure an XML file can be processed in PowerShell but it would be easier if the thing that produces an XML file could just list the job names in a text file and then you could use the same pattern John uses to enumerate servers.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Devesh_Srivastava avatar image Devesh_Srivastava commented ·
Hi David, It could a text file as well. Please let me know the possible solution as I am new to SMO programming and dont have any idea what and how to make changes here. Thanks Devesh
0 Likes 0 ·
David Wimbush avatar image
David Wimbush answered
I'm afraid I don't know enough PowerShell to help you change it but the idea would be to connect to the server once and then loop through the file, finding each job in the Jobs collection and scripting it out. It still seems like your requirements are a little odd though. You could just put the one server name in the servers file and use John's code as it is. The only difference would be that you would have all the jobs scripted out instead of just some of them. Does it matter if more than just the listed jobs are in the output? (Just a thought.)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Devesh_Srivastava avatar image Devesh_Srivastava commented ·
Jobs have to be listed in an input file as everytime the jobs would not be same, they could different since all the jobs would not be of our interest to be scripted and included in the script.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.