As a DBA when we have lots of shared location and ForFiles does not work and throws the below error
ERROR: UNC paths (\\machine\share) are not supported.
The procedure will be helpful to delete the files. The procedure needs to be run by providing the below details.
exec DeleteOldFiles @path= '\\sharelocation$\servename\transactional_logs\',
@days = -15
To extract the date, sbustring function is used in the procedure. Please make changes as necessary. In my case, I had the DatabaseName_Datetime.trn