The script is available for download from https://gallery.technet.microsoft.com//How-to-delete-SQL-Server-9699b96a. You can also use Microsoft Script Browser for Windows PowerShell ISE to download the sample with one button click from within your scripting environment.
This T-SQL script is used to delete backup files you don’t want to keep in a folder. It will demonstrate how to do achieve it by using master.dbo.xp_delete_file. We will provide the file path, backup file extension and the time line. With the stored procedure in this script, we will delete the backup files older than the time line we entered.
As there are so many backup files in a folder, and we need delete some files older than a specified time. The script will only be used to delete backup files generated by SQL Server.
You can find more All-In-One Script Framework script samples at https://aka.ms/onescriptingallery