Skip to content

Instantly share code, notes, and snippets.

@Otterpohl
Created May 13, 2022 16:17
Show Gist options
  • Select an option

  • Save Otterpohl/a75ffbf2e33aa8f75d1364e4e3a8dd77 to your computer and use it in GitHub Desktop.

Select an option

Save Otterpohl/a75ffbf2e33aa8f75d1364e4e3a8dd77 to your computer and use it in GitHub Desktop.

Revisions

  1. Otterpohl created this gist May 13, 2022.
    7 changes: 7 additions & 0 deletions Set-AgentJobOwnerToSA
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    SELECT 'EXEC msdb.dbo.sp_update_job @job_id=N''' + CAST(j.job_id AS VARCHAR(150)) + ''', @owner_login_name=N''sa'' '
    FROM msdb.dbo.sysjobs AS j
    INNER JOIN master.sys.syslogins AS L
    ON j.owner_sid = L.sid
    INNER JOIN msdb.dbo.syscategories AS C
    ON C.category_id = j.category_id
    WHERE msdb.dbo.SQLAGENT_SUSER_SNAME(j.owner_sid) <> 'sa';