I am having some trouble trying to select sub OU's within an AD structure:
_________________________________
Sub GetOUs(Path)
Set OUs = GetObject("LDAP://" & Path)
OUs.Filter = Array("organizationalUnit")
For Each OU In OUs
strOUName = OU.name
strGroupDesc = OU.ou
'
' Input OU header information into spreadsheet, start counting OU's
'
iTotOU = iTotOU + 1
intGroup = intIndex
xlSheet.Cells(intIndex, 1).Value = strOUName
xlSheet.Cells(intIndex, 7).Value = strGroupDesc
strGroupId = """" & strOUName & """"
'
' Start formatting the user data cells
'
With xlSheet.Range("A" & intIndex & ":G" & intIndex)
.Font.Bold = True
.Font.Size = 10
.Interior.ColorIndex = 14
.Interior.Pattern = 1 'xlSolid
.Font.ColorIndex = 2
.Borders.Weight = xlThick
End With
'
' intIndex equals the number of cells to count down before writing data
' Appended data starts being written on the next row in column A, i.e. A5, A6, etc.
'
intIndex = intIndex + 1
iTotUsersOU = 0
GetUsers OU.distinguishedName
GetOUs OU.distinguishedName
Next
End Sub
_________________________________
How can I further filter the OU's. I tried the following statement after line 5 with no results:
If OU.ou = "Contractor" Then
_________________________________
Sub GetOUs(Path)
Set OUs = GetObject("LDAP://" & Path)
OUs.Filter = Array("organizationalUnit")
For Each OU In OUs
strOUName = OU.name
strGroupDesc = OU.ou
'
' Input OU header information into spreadsheet, start counting OU's
'
iTotOU = iTotOU + 1
intGroup = intIndex
xlSheet.Cells(intIndex, 1).Value = strOUName
xlSheet.Cells(intIndex, 7).Value = strGroupDesc
strGroupId = """" & strOUName & """"
'
' Start formatting the user data cells
'
With xlSheet.Range("A" & intIndex & ":G" & intIndex)
.Font.Bold = True
.Font.Size = 10
.Interior.ColorIndex = 14
.Interior.Pattern = 1 'xlSolid
.Font.ColorIndex = 2
.Borders.Weight = xlThick
End With
'
' intIndex equals the number of cells to count down before writing data
' Appended data starts being written on the next row in column A, i.e. A5, A6, etc.
'
intIndex = intIndex + 1
iTotUsersOU = 0
GetUsers OU.distinguishedName
GetOUs OU.distinguishedName
Next
End Sub
_________________________________
How can I further filter the OU's. I tried the following statement after line 5 with no results:
If OU.ou = "Contractor" Then