Zend certified PHP/Magento developer

Run forfiles.exe as a scheduled task, fails with return code 2147942401

I’m trying to run forfiles.exe as a scheduled task on a half dozen servers, in order to periodically delete old IIS log files. I have it running as SYSTEM, and I have it set to run with highest privileges. I also tried it with my own admin account, but it failed then as well. I’ve tried it configured for both Server 2008 R2 and Server 2019, but neither make a difference.

It’s running forfiles.exe (including the full path makes no difference), with the following as the argument:

Forfiles.exe -p C:inetpublogsLogFilesW3SVC1 -m *.log -d -30 -c “Cmd.exe /C del @path”

However, I can run it from the command line/PowerShell without issue (under my own creds, I haven’t tried launching PowerShell as system and trying it, but I doubt it would make a difference). I’m also not seeing errors in the event log anywhere, other than in the Task Scheduler section, which just basically shows the return code 2147942401.

Does anyone have any ideas?