Ah, you'll probably need to create an Agent job and specify it as a Powershell type. Using xp_cmdshell may work, but it doesn't have the flexibility of Powershell. Here's the script I use to clean up transaction log backups older than 14 days, altered a bit:
$a = Get-ChildItem "<drive>:\<folder>" -recurse
foreach($x in $a)
{
$y = ((Get-Date) - $x.CreationTime).Days
if ($y -gt 14 -and $x.PsISContainer -ne $True)
{$x.Delete()}
}
Replace the <drive> and <folder> parts as needed with your filesystem locations, and adjust <if ($y -gt 14) to your desired number of days.
Keep in mind this will delete ALL files older than the specified number of days in the provided location, regardless of type; if you need file-extension filtering, I may be able to alter it as needed. Also, of course, test this in a disposable directory to make sure it's doing what you need it to.
- 😀