Furthermore, the script targets files with ".ldf" extension. What happens if a DBA creates a database and gives one of the data files on a database the ".ldf" extension 😉
At least filter the files in sys.master_files by their type (0 = rows, 1 = log)
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉