Script to Analyze Mount Point Space & Generate Shrink File Statements

In my organization, we often receive far too many incidents for low free disk space. As part of resolution we have to check for unexpected files/folders on the mount point drive and delete/move to other location. There are also times when we are left with no other option but to Shrink the database files present on the mount point drive. Below script serves the same purpose. Script requires only 2 inputs namely @Path and @FreeSpaceThresholdInPercent. Then it analyzes all the database files of instance falling under same mount point as of @path, and presents the general information like Total Size, Available space, free space, and more space to add to meet the threshold requirement. Also, it then generates DBCC SHRINKFILE commands for all the affected files in decreasing order of space available. It also displays running total of approx., space freed with each shrink operation.

percent-free-space

Friends, please feel free to correct me by comments. Also, comment if you find the script useful. Kindly suggest any suggestion that you feel could make the script better and useful. If you like the article, do Like & Share. Happy Coding 🙂

Leave a Reply