SELECT 'USE [' + db.name + '] ALTER DATABASE [' + db.name + '] SET RECOVERY SIMPLE DBCC SHRINKFILE (''' + mf.name + ''', 1) ALTER DATABASE [' + db.name + '] SET RECOVERY FULL' AS ShrinkScript, db.name AS DBName, mf.name AS LogName, mf.physical_name AS Location, mf.size AS LogFileSize FROM sys.master_files mf INNER JOIN sys.databases db ON db.database_id = mf.database_id WHERE mf.type = 1 AND mf.size > 10 AND db.owner_sid <> 0x01 -- SYSTEM DATABASE ORDER BY mf.size DESC;