Having issues in retreiving direct reports recursively from AD using VB Script.

Author Message
pbalajieie

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 11/17/2011
  • Status: offline
Having issues in retreiving direct reports recursively from AD using VB Script. Thursday, November 17, 2011 9:44 AM (permalink)
0
Hi,
This is my first ever post in this forum!!!
I need a help from you guys in fixing a script which I’ve created (thanks to various sources in the internet ) to generate all the direct and subsequent child reportees for the direct reportees for a given employee.
It works well for the direct reportees as well as for the 1st set of child reportees then the script collapses @ throws "Object not a collection" @ line# 74.
Hope you guys shower me the guidance light to fix it while I continue my quest in fixing it.
Here is the script for your reference and thanks in advance!
 Option Explicit 
Dim objExcel : Set objExcel = CreateObject("Excel.Application") 
With objExcel 
    .Visible = True 
    .DisplayAlerts = False 
    Dim objWorkBook : Set objWorkBook = .WorkBooks.Add 
    Dim objSheet : Set objSheet = .Worksheets(1) 
End With 
Create_Excel_Header() 
Dim intRow : intRow = 2
Dim objItem, objUser1,objUser12, intColumn 
Dim strUser : strUser = "Username" 
Dim objUser : Set objUser = GetObject("LDAP://" & GetDN(strUser)) 
Enum_Members(objUser) 
Format_It() 
Save_It() 
Sub Create_Excel_Header() 
    With objSheet 
        .Name = "Data" 
        .Cells(1, 1).Value = "UserName" 
        .Cells(1, 2).Value = "First Name" 
        .Cells(1, 3).Value = "Last Name" 
        .Cells(1, 4).Value = "Title" 
        .Cells(1, 5).Value = "Company" 
        .Cells(1, 6).Value = "Department" 
        .Cells(1, 7).Value = "Manager Name"     End With 
    Dim objRange : Set objRange = objSheet.UsedRange 
    objRange.Select 
    With objRange 
        .Font.Bold = True 
        .Font.Name = "Arial" 
        .Font.Size = 10 
        .WrapText = False 
        .HorizontalAlignment = -4108 
        .Interior.ColorIndex = 37 
        .Cells.RowHeight = 25        
    End With 
End Sub 
Sub Format_It() 
    Const xlEdgeBottom = 9 
    Const xlEdgeLeft = 7 
    Const xlEdgeRight = 10 
    Const xlEdgeTop = 8 
    Const xlInsideHorizontal = 12 
    Const xlInsideVertical = 11 
    Const xlContinuous = 1 
    Const xlAutomatic = -4105 
    Const xlMedium = -4138 
    Dim objRange : Set objRange = objSheet.UsedRange 
    objRange.Select 
    
    objRange.Columns.AutoFit 
    Dim arrBorders : arrBorders = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight, xlInsideVertical, xlInsideHorizontal) 
    Dim intBorder 
    For Each intBorder in arrBorders 
        With objRange.Borders(intBorder) 
            .LineStyle = xlContinuous 
            .Weight = xlMedium 
            .ColorIndex = xlAutomatic 
        End With 
    Next 
End Sub 
Sub Save_It() 
    objExcel.ActiveWorkBook.SaveAs("H:\child_report.xls") 
    objExcel.Quit 
End Sub 
Sub Enum_Members(User) 
    Dim arrAttributes : arrAttributes = Array("samaccountName", "GivenName", "sn", "Title", "company", "department", "manager") 
   Dim objItem
    For Each objItem in User.directreports             intColumn = 1            Set objUser1 = GetObject("LDAP://" & objItem)
 Dim arrAttributes1: arrAttributes1 = Array(objUser1)
            Dim strAttrib 
            For Each strAttrib in arrAttributes 
                On Error Resume Next 
                objSheet.Cells(intRow, intColumn).Value = objUser1.Get(strAttrib) 
                On Error GoTo 0 
                intColumn = intColumn + 1 
            Next 
           
        intRow = intRow + 1 
Next
Dim objItem12 For Each objItem12 in arrAttributes1 Call Enum_Members(objItem12) 
         
Next End Sub 
Function GetDN(samAccount) 
      If Not IsObject(objWSHNetwork) Then 
        Dim objWSHNetwork : Set objWSHNetwork = WScript.CreateObject("WScript.Network") 
      End If 
      Dim NT : Set NT= CreateObject("NameTranslate") 
      NT.Init 3, "" 
      NT.Set 3, objWSHNetwork.UserDomain & "\" & samAccount 
      GetDN = NT.Get(1) 
End Function 

<message edited by pbalajieie on Thursday, November 17, 2011 10:54 AM>
 
#1
    themcse

    • Total Posts : 171
    • Scores: 1
    • Reward points : 0
    • Joined: 12/29/2008
    • Status: offline
    Re:Having issues in retreiving direct reports recursively from AD using VB Script. Sunday, November 27, 2011 6:02 PM (permalink)
    0
    What is line 74 in your script?  When I pasted this out, it looks like it's an "On Error Resume Next" which I would assume to be incorrect.  For the users where you are experiencing this issue, is it plausible that they have no direct reports?  Kind regards.
     
    #2

      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