Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Exception Handling

Status
Not open for further replies.

electro93

MIS
Mar 29, 2004
5
US
Hey please check out the script below. I have a script that has exported CNs with attributes and I am writing a script that checks an OU to see if they've been added. If they haven't been added, I create the user and apply attributes (i.e. first name, location, etc). If the user already exists I just want to modify those attributes. Any insight is very much appreciated. Thanks!!

_________________________________________________________


Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile _
("Exported_Users.txt", ForReading)

'###############################################################
'## Enter the OU that you would like to impor the users to ####
'##
'##

LDAP_NAME = information here.....

'###############################################################


Set objOU = GetObject _
("LDAP://" & LDAP_NAME)

objOU.Filter = Array("user")

Do Until objFile.AtEndOfStream
strUser = objFile.Readline
GivenName = objFile.Readline
SN = objFile.Readline
City = objFile.Readline
State = objFile.Readline
Zipcode = objFile.Readline
Telephone = objFile.Readline
Title = objFile.Readline
Department = objFile.Readline
Company = objFile.Readline
DisplayName = objFile.Readline
Mail = objFile.Readline
Break_Loop = 0
User_Added = 0


###################
Set objCheck = GetObject ("LDAP://" & strUser & "," & LDAP_NAME)

This is the problem statement. If it returns "NULL" the program dies. How to I catch the null statement and move on? Thanks!!!!!!!!!
##############################
if objCheck.sn = SN and objCheck.givenName = GivenName Then
Wscript.Echo "The User has been matched..."
User_Added = 1
End If

If User_Added = 0 Then
Wscript.echo "Name: " & strUSer
Wscript.echo "First Name: " & GivenName
Wscript.echo "Last Name: " & SN
Wscript.echo "City: " & City
Wscript.echo "State: " & State
Wscript.echo "ZipCode: " & Zipcode
Wscript.echo "Telephone: " & Telephone
Wscript.echo "Title: " & Title
Wscript.echo "Department: " & Department
Wscript.echo "Company: " & Company
Wscript.echo "DisplayName: " & DisplayName
Wscript.echo "Mail: " & Mail
End If
Loop

Wscript.Echo "All contacts have been successfully imported into: " & LDAP_NAME
 
will
If IsNull(objCheck) Then

do you?
or,
If IsObject(objCheck) Then
??
 
What is the EXACT error message when your program dies ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
The problem is that when this statement executes:

GetObject ("LDAP://" & strUser & "," & LDAP_NAME)

If the value returned is null, than the script will bomb. Is there a way to catch that exception? I tried using

If IsNull(GetObject ("LDAP://" & strUser & "," & LDAP_NAME)) Then


but that bombs with same error as well. Thanks for the help though!!!

 
D:\Scripts\test_import.vbs(38, 3) (null): There is no such Object on the server.
 
Try something like this:
On Error Resume Next
Set objCheck = GetObject("LDAP://" & strUser & "," & LDAP_NAME)
If Err.Number > 0 Then
WScript.Echo "User " & strUser & ", Error " & Err.Number _
& vbCrLf & Err.Description
On Error GoTo 0
Err.Clear
Else
On Error GoTo 0
...
End If

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top