Getting an error with an input file

Author Message
Frank69for2

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 12/2/2011
  • Status: offline
Getting an error with an input file Friday, December 02, 2011 5:36 AM (permalink)
0
Hi, I am having trouble with my script reading a file and putting it in a variable. I trying to query multiple child domains and it will fail on the bolded parts. Can someone help.
 
Const ForWriting = 2  
Const ForAppending = 8

Set Objfso = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objfso.OpenTextFile("Domains.txt", 1, True)
Set objOutputFile = objfso.CreateTextFile("ChildDCUsers.txt")
set objFolder = nothing
set objOutputFile = nothing
Set objDomain = nothing
Set objTextFile = objFSO.OpenTextFile ("ChildDCUsers.txt", forWriting)
strText0 = "Employee Number,Name,First Name,Last Name,Title,Email,Location,User ID"
objTextFile.WriteLine(strText0)
objTextFile.Close


Do While objInputFile.AtEndOfLine <> True ' Comment out this line for a single server
strDomain = objInputFile.ReadLine

Set objRoot = GetObject("LDAP://RootDSE") 
Set objDomain = GetObject("LDAP://dc="& strDomain &",dc=ci,dc=org")

Call enummembers(objDomain)

Sub enumMembers(objDomain)
For Each objMember In objDomain  

If ObjMember.Class = "user" Then
If Not (isempty(ObjMember.samAccountName)) Then SamAccountName = ObjMember.samAccountName else SamAccountName = "" End If
If Not (isempty(ObjMember.CN)) Then Cn = ObjMember.CN else Cn = "" End If
If Not (isempty(objMember.GivenName)) Then FirstName = objMember.GivenName else FirstName = "" End If
If Not (isempty(objMember.sn)) Then Lastname = ObjMember.sn else LastName = "" End If
If Not (isempty(objMember.C)) Then C = objMember.C else Country = "" End If
If Not (isempty(objMember.Mail)) Then Mail = objMember.Mail else Email = "" End If
If Not (isempty(ObjMember.description)) Then description = ObjMember.description else description = "" End If

set objFolder = nothing
set objFile = nothing

Set objTextFile = objFSO.OpenTextFile ("ChildDCUsers.txt", ForAppending, True)
strText1 = Mail & "," & CN & "," & FirstName & "," & LastName & "," & Description & "," & Mail & "," & C & "," & SamAccountName
objTextFile.WriteLine(strText1) 
objTextFile.Close

Mail = ""
samAccountName = ""
GivenName = ""
sn = ""
C = ""
description = ""
End If 
If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then 
enumMembers (objMember) 
End If
Loop
Next
End Sub
 
#1
    59cobalt

    • Total Posts : 969
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Getting an error with an input file Friday, December 02, 2011 9:58 AM (permalink)
    0
    What is the value of strDomain when the script fails, and what is the exact error you get (error number and error description)? And use .AtEndOfStream instead of .AtEndOfLine, because otherwise your loop will exit at the first blank line.

    As a side note (because it just poked me in the eye), don't use statements like this:
    Do While objInputFile.AtEndOfLine <> True
    While technically correct, the "phrasing" is far more complicated than it needs to be. Conditions are evaluated to boolean values anyway, so comparing the boolean value of .AtEndOfLine to a boolean constant in order to get a boolean value is redundant. Just use the original boolean value (or in this case the negated value):
    Do While Not objInputFile.AtEndOfLine
    This can be simplified even more, because While Not is equivalent to Until:
    Do Until objInputFile.AtEndOfLine
    Granted, it's not a big deal here. However, if you make a habit of keeping your statements as simple and straightforward as possible, your code in general will become a lot easier to understand (and to maintain).
     
    #2
      Frank69for2

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 12/2/2011
      • Status: offline
      Re:Getting an error with an input file Monday, December 05, 2011 3:54 AM (permalink)
      0
      Hi 59Cobalt, I get the following error on the Sub enumMembers(objDomain) line:
      C:\Users\frankc\Documents\usersearch9a.vbs(30, 1) Microsoft VBScript compilation error: Syntax error
      If I comment out everything below the Call subfunction and do wscript.echo strDomain, it will show the results of the file. If I try to do a wscript.echo objDomain, I get a Runtime error: Type mismatch.
      Hope this helps.
      Thanks
       
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:Getting an error with an input file Monday, December 05, 2011 4:09 AM (permalink)
        0
        For a Sub you do not use Call or () around parameters. So try changing this:
         
        Call enummembers(objDomain)
         
        To this:
         
        enummembers objDomain
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          59cobalt

          • Total Posts : 969
          • Scores: 91
          • Reward points : 0
          • Joined: 7/17/2011
          • Status: offline
          Re:Getting an error with an input file Monday, December 05, 2011 8:48 AM (permalink)
          0
          It shouldn't matter whether he uses
          Call enummembers(objDomain)
          or
          enummember objDomain
          Both variants are valid.

          I suspect the issue is with something like calling IsEmpty() on an attribute that doesn't have a value.
           
          #5
            Frank69for2

            • Total Posts : 3
            • Scores: 0
            • Reward points : 0
            • Joined: 12/2/2011
            • Status: offline
            Re:Getting an error with an input file Tuesday, December 06, 2011 2:08 AM (permalink)
            0
            It seems that I don't even get that far. I am going to try an array to see if I get results on just getting to the domain. Stay tuned...
             
            #6

              Online Bookmarks Sharing: Share/Bookmark

              Jump to:

              Current active users

              There are 0 members and 1 guests.

              Icon Legend and Permission

              • New Messages
              • No New Messages
              • Hot Topic w/ New Messages
              • Hot Topic w/o New Messages
              • Locked w/ New Messages
              • Locked w/o New Messages
              • Read Message
              • Post New Thread
              • Reply to message
              • Post New Poll
              • Submit Vote
              • Post reward post
              • Delete my own posts
              • Delete my own threads
              • Rate post

              2000-2012 ASPPlayground.NET Forum Version 3.9