I can run a script from Powershell to delete sharepoint files, but as soon I create a task the script starts but does not complete the task. I have added a line to the script to launch Powershell
Add-PsSnapin Microsoft.SharePoint.PowerShell
get-childitem D:\Backupfarm\PFS -recurse | where {$_.lastwritetime -lt (get-date).adddays(-7) -and -not $_.psiscontainer} |% {remove-item $_.fullname -force}