Hi Andrew,
I have created this for you from a similar maintenance task I undertake:
EXEC sp_MSforeachdb 'IF ''?'' NOT IN (''tempDB'',''model'',''msdb'', ''master'')
BEGIN
DECLARE @desiredSizeInMB INT = 16, @execSQL NVARCHAR(MAX)
SELECT @execSQL =
''DBCC SHRINKFILE ('' + NAME + '' ,'' + CAST(@desiredSizeInMB AS VARCHAR(4)) + '' ) WITH NO_INFOMSGS;''
FROM
[?].[sys].[database_files] AS DF
WHERE
[type] = 1
use [?];
EXEC sp_executesql @execSQL
END'
Edited - actually execute the SQL!
🙂
gsc_dba