Question : Vbs script to get group membership count. Does not get actual count for some groups.

Hi,

Vbs script to get group membership count. Does not get actual count for some groups.
For some groups that are 0 it gets the previously scanned group no's

Can anyone help to fix the issue.

REgards
sharath
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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
domainPath = "DC=lth,Dc=local"
orgUnitPathForGroups = "OU=Distri,OU=Offices"
 
objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://" & orgUnitPathForGroups & "," & domainPath & "' WHERE objectCategory='group'"  
Set objGroupRecordSet = objCommand.Execute
 
objGroupRecordSet.MoveFirst
Do Until objGroupRecordSet.EOF
    
 
    Set objGroup = GetObject _
      ("LDAP://cn=" & objGroupRecordSet.Fields("Name").Value & "," & orgUnitPathForGroups & "," & domainPath)
    objGroup.GetInfo
 
    arrMemberOf = objGroup.GetEx("member")
 
    i = 0
'   WScript.Echo "Members:"
    For Each strMember in arrMemberOf
'        WScript.echo "   " & strMember
        i = i+1
    Next
 
    Wscript.Echo "Group: [" & objGroupRecordSet.Fields("Name").Value & "] Members: " & i
 
    objGroupRecordSet.MoveNext
Loop

Answer : Vbs script to get group membership count. Does not get actual count for some groups.

The update below will match whole strings


hth

Dave

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
ub createhyperlink()
    Dim ws As Worksheet
    Dim ws1 As Worksheet
    Dim rng As Range
    Dim c As Range
    Dim rng2 As Range

    Set ws = Sheets("Sheet1")
    Set ws1 = Sheets("Sheet2")
    Set rng = ws1.Range("a2:A" & ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row)

    For Each c In rng
    If c.Value <> "" Then
        x = c.Value
        Set rng2 = ws.Columns(1).Find(What:=x, after:=ws.Cells(1), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If Not rng2 Is Nothing Then ws.Hyperlinks.Add Anchor:=c, Address:="", SubAddress:="" & ws.Name & "!" & rng2.Address(0, 0) & "", TextToDisplay:=c.Value
        End If
    Next c
End Sub
Random Solutions  
 
programming4us programming4us