Changing string in all objects in all databases on one server Is there a way to find all instances of a string in all objects of all databases on one server?

The reason behind this question is that we need to change a reference to another database (located on another server). 

So, we need to find every view, stored procedure, function, etc. that has a reference to the old server. This search also needs to include objects that are not specific to a single database, like system jobs.

So far, the best way I know of doing this is to use the Generate Script wizard on each database individualy and then search for the string in the generated files. The problem with this approach is that it ignores system jobs.

Is there a better way of doing this?

UPDATE 1

I looked into the sys.sql_modules table and that looks like a good alternative to the Generate Scripts wizard.

I have a query for one database that works fine by itself

select 
'MyDatabaseName' as DbName,
o.name as ObjectName,
o.type_desc as ObjectType,
m.definition as Definition
from MyDatabaseName.sys.sql_modules m 
inner join sys.objects o on m.object_id = o.object_id
WHERE m.definition Like '%MyString%'


But when I try to use it with sp_msforeachdb, I don't get the same amount of results.

DECLARE
    @SQL nvarchar(4000)
SET @SQL='select ''?'' as DbName, o.name as ObjectName, o.type_desc as ObjectType, m.definition as Definition from [?].sys.sql_modules m inner join sys.objects o on m.object_id = o.object_id where m.definition like ''%MyString%'''
EXEC sp_msforeachdb @SQL


Even when removing the condition for MyString I still don't get the same number of results (from 267 to 27).

Using msforeachdb would really help me because I need to run this on many databases over many servers.

UPDATE 2

Found the issue in my query, it was missing a [?] in front of the joined sys.objects. Here's the corrected query

DECLARE
    @SQL nvarchar(4000)
SET @SQL='select ''?'' as DbName, o.name as ObjectName, o.type_desc as ObjectType, m.definition as Definition from [?].sys.sql_modules m inner join [?].sys.objects o on m.object_id = o.object_id where m.definition like ''%MyString%'''
EXEC sp_msforeachdb @SQL
sp_msforeachdb is undocumented. There are viable alternatives to it.

Try changing:

SET @SQL='select ''?'' as DbName, o.name as ObjectName, o.type_desc as 
 ObjectType, m.definition as Definition from [?].sys.sql_modules m inner join sys.objects o on m.object_id = o.object_id where m.definition like ''%MyString%'''

to:

SET @SQL='USE [?]; select Db_Name(), o.name as ObjectName, o.type_desc as ObjectType, m.definition as Definition from sys.sql_modules m inner join sys.objects o on m.object_id = o.object_id where m.definition like ''%MyString%'''

As originally written, the @SQL's sys.objects will reference the database being used for sp_msforeachdb's execution and thus the statement's 2 object_id values may or may not join.