Not saying this is what is throwing the error, but you call the UDF UserInLocalGroup() but the failed return is $UserInGroup.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.