Skip to content

Instantly share code, notes, and snippets.

@davops
Created April 18, 2016 18:54
Show Gist options
  • Save davops/2847b03c6acb9c7527a2b21fcd765eb8 to your computer and use it in GitHub Desktop.
Save davops/2847b03c6acb9c7527a2b21fcd765eb8 to your computer and use it in GitHub Desktop.
This query looks through all databases for objects using the xp_cmdshell command. The original select query originally came from: http://stackoverflow.com/questions/2833389/finding-all-stored-procedures-calling-a-function
EXEC sp_MSForEachDB ' Use [?]; SELECT DB_NAME() AS ''Database Name'';
Select *
FROM sys.sql_modules m
INNER JOIN sys.objects o ON m.object_id=o.object_id
INNER JOIN sys.schemas s ON o.schema_id=s.schema_id
WHERE m.definition Like ''%xp_cmdshell%''
ORDER BY 1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment