Changing the SQL Agent Job properties in one go

I was installing a new version of a vendor application and one of the requirements was to change the existing sql agent job owners to a different user account.

There were several jobs and I needed to find a way to script them out and do it all at once and all these jobs had the same naming convention, so,it was possible for me to do wild character search. Below is how I did,

'EXEC msdb.dbo.sp_update_job @job_id=N'''+cast(Job_ID as varchar(100))+''',
@owner_login_name=N''NewJobOwner''' from msdb.dbo.sysjobs A
INNER JOIN master.dbo.syslogins B on A.owner_sid=B.sid
where A.enabled = 1 and like '%--NAMEoftheJOBS--%' and
B.loginname= '--OldJobOwner--'

Copy the output of this into SSMS and Execute.

Alternatively, I could use loop or cursor and update one by one but I liked the above method.