Thanks everybody for the suggestions.
I think I will try the ComputerInGroup() UDF as suggested by Allen.
I just found that there is a redundant $-sign in the script.