Two quick comments regarding cleanup..
1 - You can't set the @ERROR or @SERROR macros.. they are read only.
2 - Most UDFs should be silent. If you want to return status, you should return a code or string in the function's private variable (ie: $FuncName)
As for standards, make sure all vars are declared to avoid "accidental globals" from messing with your code. For public functions, I like to declare each var on its own line and add a short comment to define what the var (or set of vars) is used for.
Since these functions are inter-related, you could create a function library with a single standard header, and separate syntax statements for each function.
Also, for enhanced flexibility, I'd consider passing the group name as an additional arg, and changing AddLocalAdmin(AccountID) to JoinLocalGroup(AccountID, GroupID).
Needs just a bit of polish, but there's a gem of a library waiting to come out of this!
Glenn
_________________________
Actually I
am a Rocket Scientist!