I have the following script. It seems to be ending prematurely. I added the commented out lines in order to make sure it got all the proper items(which it did). For some reason though it will end with no given error at random locations in the script. Any ideas?

Code:

$ldap="LDAP://corp/OU=CLN Computers, OU=CLN-Clinton, OU=Bearing, DC=corp, DC=timken, DC=com"
$Computers = GetObject($Ldap)

;For Each $Computer in $Computers
; ? Right($Computer.Name,Len($Computer.Name)-3)
;Next
;Get $x
;If $x = "q"
; Exit
;EndIf

WriteLog($LogFileName, "script started")
For Each $Computer in $Computers
$ComputerName = Right($Computer.Name,Len($Computer.Name)-3)
? "Processing $ComputerName"
If (UserInLocalGroup($ComputerName, "Users" , "Domain Users") = 'True')
RemoveUserFromGroup($computerName, "Users", "Corp\Domain Users")
EndIf
Next
WriteLog($LogFileName, "Script completed")

Function UserInLocalGroup($ComputerName, $Group, $User)
$GroupObj = GetObject("WinNT://" + $ComputerName + "/" + $Group)

$FlagFound = 'False';
For Each $UserObjG IN $GroupObj.Members
If $UserObjG.Name = $User
$FlagFound = 'True'
EndIf
Next
$UserInLocalGroup = $FlagFound
EndFunction

Function RemoveUserFromGroup($Computer, $Group, $User)
; Log the fact this machine has the group in its list and then remove it from the list
WriteLog($LogFileName, "$Computer contains " + Chr(34) + $User + Chr(34) + " in " + chr(34) + $Group + Chr(34))
$ShellStr = "C:\grpmaint.exe --Sam \\" + $Computer + " --remove --name $Group --member " + Chr(34) + "$User" + Chr(34) + " --logfile " + Chr(34) + "$LogFileName" + Chr(34)
Shell $ShellStr
EndFunction

Function AddUserToLocalGroup($Computer, $Group, $User)
; Ranamed from GroupAdd (http://www.kixtart.org/ubbthreads/showflat.php?Number=81735)
; Variables Modified $Target = $Computer, $ObjToAdd = $User
DIM $computer, $group, $User, $obj, $objhome

If SubSTR($computer,1,2) = '\\'
$computer = SubSTR($computer,3,Len($computer))
EndIf
If InSTR($User,'\') <> 0
$User = Split($User,'\')
If UBound($User) <> 1 Exit 13 EndIf
$objhome = $User[0]
$obj = $User[1]
Else
$objhome = $computer
$obj = $User
EndIf

$group = GetObject('WinNT://' + $computer + '/' + $group)
If VarType($group) = 9 and @ERROR = 0
$group.Add ('WinNT://'+$objhome+'/'+$obj)
Else
$GroupAdd = @ERROR
Exit @ERROR
EndIf
$GroupAdd = @ERROR
Exit @ERROR
EndFunction

Function WriteLog ($LogFile, $LogString)
If Open(1, $LogFile, 5) = 0
$LogString = "@MONTHNO.@MDayNo.@Year @TIME " + $LogString + @CRLF
$result = WriteLine (1, $LogString)
Close(1)
Else
BEEP
? "Failed to open Log file(Error[" + @Error + "]) "
EndIf
EndFunction




I left out the additional documentation comments that was included in GroupAdd for brevity.