Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Ownership of manyJob via script 1

Status
Not open for further replies.

Corran007

Programmer
May 20, 2002
530
US
Does anyone have a script or know of one already made that searches through all the jobs of a server for one user and replaces them with another user?

I just realized some jobs i made are owned by me not the account i want them to be.

thanks in advance
 
The following script generates the a script for chaning the Job Owner. Run this query in Query Analyzer. Copy the result to the clipboard and paste in a new query window. Execute it to change the owner of the listed jobs.

Select
[Use msdb]='Exec sp_update_job @job_id = ''' +
convert(varchar(85),j.job_id) +
''', @owner_login_name = ''newowner''' +
char(10) + '--' + j.name +
' is currently owned by ' + l.name
From msdb.dbo.sysjobs j
Left Join master.dbo.syslogins l
On j.owner_sid=l.sid
Where l.name='oldowner'
Or l.sid is null If you want to get the best answer for your question read faq183-874 and faq183-3179.
Terry L. Broadbent - DBA
SQL Server Page:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top