I know how to script a stored procedure using PowerShell and SMO:
[System.reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | out-null
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server"
$srv.databases['MyDatabase'].StoredProcedures['MyProc'].TextBody
But since I want to use the procedure text within a query, I wonder whether I can call SMO in some way within pure T-SQL.
Must only run in development environment.
BTW: A function returning the definition of a stored procedure with a given name would solve my current problem but not answer my question.
Edit:
I want to find which procedures reference a given table when I use this query:
SELECT p.name --, definition
FROM sys.sql_modules m
join sys.objects p on m.object_id = p.object_id
where p.type = 'P'
and definition like '%SearchForThis%'
That is exactly the same information I want to get using SMO.