The code below, get a list of non system databases, set the database to readonly and then shrink the file.
I have kept this code in a few SQL Server boxes using SQL Agent Job, where space is always an issue.
On Sat/Sun night every week, it start running and shrink all the databases within few hours (depending upon the size of databases).
declare @db varchar(255) |