One way this can go wrong without it even being particularly obvious is if you think you're getting drive resources in one of your subqueries from a mapped drive but it turns out that it's a UNC instead. The inserted sub functions weren't shelling out errors and it turned out that my own script was failing to pull a resource because of that (with the same strange caveat that it would work just fine if I tried running the .ps1 script with the drive letter assigned to the UNC from command prompt but it would fail without error if I tried running it from Task Scheduler).
This might be a rare case but I'd still rather save who I can the search that I just had to do.