For starters, configure the scheduled task to execute a bat file which calls the Powershell script. Have it capture stdout and stderr so that you can see what messages Powershell produces.
https://learn.microsoft.com/en-us/answers/questions/2141466/how-to-run-a-task-with-task-scheduler
If you need additional information have your script generate a transcript.
Put a start-transcript at the beginning of the script and a stop-transcript at the end.
Add troubleshooting statements in your script to display key processing points and what data it sees.
"About to look for files"
$files = Get-Childitem -path "C:\whatever"
"We found {0} files." -f $files.count