But it works in my Environment - Tips for writing scripts someone else will run

TL:DR; Your scripts have too much in them and make too many assumptions, simplify them

One of the things I do in my day job is orchestrate procedures for a large enterprise. One that takes security seriously and so won’t give more rights than needed out.