Question : VBScript to check if a account exist then what memebership it has

could someone help with this small script?

I'm sure this could be a simple if then problem.  But, have no idea of how to start.

the atached script is designed to search 2 domains and return the membership for accounts with the same name. if both accounts exist CS domain (win2003 AD) and CSC Domain (NT4) then the spript runs great.   it returns a message that shows what members ship the accounts have.  but if 1 domain account does not exist it errors out, instead of just out putting that the account does not exist.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Dim UserObj
Dim GroupObj

UserString = InputBox("The User name that you would like to check")


DomainString="CSC"
        List = List & "**********************************************"& VbCrLf
	List = List & DomainString & " Group Membership" & VbCrLf
        List = List & "**********************************************"& VbCrLf
	List = List & VbCrLf
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
    
    For Each GroupObj In UserObj.Groups
        List = List & GroupObj.Name & VbCrLf
    Next


DomainString="CS"
        List = List & VbCrLf
        List = List & "**********************************************"& VbCrLf
	List = List & DomainString & " Group Membership" & VbCrLf
        List = List & "**********************************************"& VbCrLf
	List = List & VbCrLf
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
    
    For Each GroupObj In UserObj.Groups
        List = List & GroupObj.Name & VbCrLf
    Next

Answer : VBScript to check if a account exist then what memebership it has

Hi, I have added error checking to get around your problem.  Also, seeing as the code is duplicated except for the DomainString, I have put in a loop with an Array for the domain names.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
Dim UserObj
Dim GroupObj

UserString = InputBox("The User name that you would like to check")

arrDomains = Array("CSC", "CS")

For Each DomainString In arrDomains
	'DomainString="CSC"
	List = List & "**********************************************"& VbCrLf
	List = List & DomainString & " Group Membership" & VbCrLf
	List = List & "**********************************************"& VbCrLf
	List = List & VbCrLf
	On Error Resume Next
	Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
	If Err.Number = 0 Then
		On Error GoTo 0
		For Each GroupObj In UserObj.Groups
			List = List & GroupObj.Name & VbCrLf
		Next
	Else
		Err.Clear
		On Error GoTo 0
		List = List & "User does not exist of " & DomainString
	End If
Next

WScript.Echo List
Random Solutions  
 
programming4us programming4us