Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Automate Pulling off agent Jobs to File


Automate Pulling off agent Jobs to File

Author
Message
jameslauf
jameslauf
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 567
Hello I just started a new position and I have been asked to go through all our SQL Servers and pull a copy of all the SQL Server Agent Jobs off to a file. I started this by just using SSMS and "Right Clicking" each Job then selecting Script Job as > Create To > File.
I was wondering is anyone had a script or that can automatically do this for all jobs on the Server? We have over 100 Servers in my new environment and some have as many as 50 jobs on them.

Any help with this would be greatly Appreciated.

Thanks
homebrew01
homebrew01
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2980 Visits: 9071
1 level of improvement is to display the job list in the "Object Explorer" pane, highlight all the jobs at once, then "Create to File" and put them all in 1 file for that server.

I do that once in a while when I want to search all the jobs for something specific.



Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45127 Visits: 39923
jameslauf (11/22/2013)
I have been asked to go through all our SQL Servers and pull a copy of all the SQL Server Agent Jobs off to a file.


Unless they told you "Why", that's a fairly ridiculous request. What do they indend to achieve from such a thing? There may be much better methods than the simple listing of SQL Server Agent jobs but they must first define what they seek.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
jameslauf
jameslauf
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 567
We are getting ready to Sunset several Servers here and we are under several regulations so I believe it is for documentation purposes.

I am new enough to this company and my DBA experience until now has been on small envinronments like 2 SQL servers and max 5 Databases.
jameslauf
jameslauf
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 567
I was able to Highlight all and copy to single file. Thanks

I am still hoping to find a way to automate this more. All help is appreciated.
KumarVelayutham
KumarVelayutham
SSC-Enthusiastic
SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)SSC-Enthusiastic (109 reputation)

Group: General Forum Members
Points: 109 Visits: 1281
Here is the script that i found ..

http://www.nilkanth.com/2004/07/18/sql-jobs-auto-backup/

Then put this script in a job and schedule it to receive the output .

Regards,
Kumar
MysteryJimbo
MysteryJimbo
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1348 Visits: 15327
I have a couple of powershell scripts which I can use to do this. I use them when I take over a role if there is little source control and just as a precaution. They are useful for migrations too.

I forget where I got this one so I can't give credit to the initial author. I added a few modifications to it so...


# Date: 23/02/12
# Description: PS script to generate all SQL Server Agent jobs on the given instance.
# The script accepts an input file of server names.
# Version: 1.0
#
# Example Execution: .\Create_SQLAentJobSripts.ps1 .\ServerNameList.txt

#param([String]$ServerListPath)

#Load the input file into an Object array
$ServerNameList = "";
#get-content -path $ServerListPath

$login = Read-Host 'Enter your SQL login'
$password = Read-Host 'Enter your password' -AsSecureString;

$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password);
$PlainPassword = [System.Runtime.InteropServices.Marshal]:TonguetrToStringAuto($BSTR);

#Load the SQL Server SMO Assemly

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Smo') | Out-Null

#Create a new SqlConnection object
$objSQLConnection = New-Object System.Data.SqlClient.SqlConnection

#For each server in the array do the following..
foreach($ServerName in $ServerNameList)
{
Try
{
#$objSQLConnection.ConnectionString = "Server=$ServerName;Integrated Security=SSPI;"
$objSQLConnection.ConnectionString = "Server=$ServerName;User Id=$login;Password=$PlainPassword"
Write-Host "Trying to connect to SQL Server instance on $ServerName..." -NoNewline
$objSQLConnection.Open() | Out-Null
Write-Host "Success."
$objSQLConnection.Close()
}
Catch
{
Write-Host -BackgroundColor Red -ForegroundColor White "Fail"
$errText = $Error[0].ToString()
if ($errText.Contains("network-related"))
{Write-Host "Connection Error. Check server name, port, firewall."}

Write-Host $errText
continue
}

#IF the output folder does not exist then create it
$OutputFolder = "C:\Scripts\Jobs\$ServerName"
$DoesFolderExist = Test-Path $OutputFolder
$null = if (!$DoesFolderExist){MKDIR "$OutputFolder"}

#Create a new SMO instance for this $ServerName
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $objSQLConnection

#Script out each SQL Server Agent Job for the server
$srv.JobServer.Jobs | foreach {$job = $_.name -replace "\*", ""; $_.Script() | out-file "$OutputFolder\$job.sql"}
}


I'll need to try and find the other one. Its much easier to follow and uses SQLPSX.
jameslauf
jameslauf
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 567
Thank You very much. Both of these should do the job. I will post once I have tried them.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search