How to get scripts to work in task/deployment?

Whenever i write a script, it will work when i run it directly on the test machine. However, when I try to put the script into a task/deployment, it wont work. Are there any extra steps I need to do, or is there something else that could be going wrong?

A lot of the time it’s because of the difference between user and system context, or between remote and local sessions. I would start with that in consideration, and if you still have some issues, then maybe redact your code a bit so it’s safe for public visibility and post it here.