Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Why is my VB script limiting results to 1500 ?

Avatar of ISG_Query
ISG_Query asked on
Active DirectoryMicrosoft ApplicationsVB Script
10 Comments1 Solution990 ViewsLast Modified:
Hi all-knowing ones !

We use the vb script below to extract the membership of a Global security group. We have a few groups with over 2000 users in them. When used, we seem unable to get it to give us more than 1500 names, regardless of the two search parameter settings. Please could you advise if this is a limitation, or can we fix it ?

Set objShell = CreateObject("Wscript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")

'*** Ask for username
strUser = Inputbox("Please enter the name of the Security Group you wish to list.")

If strUser = "" then
      Msgbox "No GroupID entered! Script will now exit."
End If

'*** Declare variables and constants

Dim con
Dim rs
Dim Com
Dim objDataScript
Const DATA_FOLDER = "C:\Scripts"
Const DATA_SCRIPT = "C:\Scripts\AD Security Group Membership results.txt"
GetADUserDetails = 0

'*** Setup an ADO query to get the values from the target object.
Set con = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set Com = CreateObject("ADODB.Command")

'*** Open a Connection object.
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"

'*** Create a command object on this connection.
Set Com.ActiveConnection = con

'*** Collect ADsPath, sAMAccountName and cn details for target object
Com.CommandText = "<LDAP://invicta.cantium.net>;(samAccountName=" & strUser & ");ADsPath,sAMAccountName,cn"

'*** Set the preferences for Search.
Com.Properties("Page Size") = 2000
Com.Properties("Timeout") = 60

'*** Execute the query.
Set rs = Com.Execute
If rs.RecordCount = 1 Then
      strPath = rs.Fields(0).Value '*** Store path to users account
      GetADUserDetails = 1 '*** User not found
End If

If GetADUserDetails = 1 then
      Msgbox "Folder name entered not found in directory."
Else       '*** User exists so continue
      If Not objFS.FolderExists(DATA_FOLDER) Then            '*** Check for folder existence, if not found then create
            Set objFolder = objFS.CreateFolder(DATA_FOLDER)
      End If
      If objFS.FileExists(DATA_SCRIPT) Then      '*** File exists so append information to it
            On Error Resume Next
            Set objDataScript = objFS.OpenTextFile(DATA_SCRIPT,8,True)
            objDataScript.WriteBlankLines (1)
            objDataScript.WriteLine "**********************************"
            objDataScript.WriteLine "*            " & strUser
            objDataScript.WriteLine "**********************************"
            Set objUser = GetObject(strPath)

            arrMemberOf = objUser.GetEx("member")
            For Each Group in arrMemberOf
          Set objGroup = GetObject("LDAP://" & Group)
          GroupCN = objGroup.CN
          objDataScript.WriteLine ""& GroupCN
            MsgBox "Finished!"
            Set objDataScript = objFS.CreateTextFile(DATA_SCRIPT,True)      '*** File does not exist so create and then write to it
            On Error Resume Next
            Set objDataScript = objFS.OpenTextFile(DATA_SCRIPT,True)
            objDataScript.WriteLine "**********************************"
            objDataScript.WriteLine "*            " & strUser
            objDataScript.WriteLine "**********************************"
            Set objUser = GetObject(strPath)

            arrMemberOf = objUser.GetEx("member")            '*** Get users group membership
      For Each Group in arrMemberOf                        '*** Loop through groups
          Set objGroup = GetObject("LDAP://" & Group)
                  '*** Check group is dist type or universal sec group
          GroupCN = objGroup.CN                                    '*** Get group name
          objDataScript.WriteLine ""& GroupCN            '*** Write group name
            MsgBox "Finished!"                                          '*** Indicate completion of process
      End If
End If


Many thanks. Any help will be hugely appreciated.
Avatar of Chris Dent
Chris DentFlag of United Kingdom of Great Britain and Northern Ireland imagePowerShell Developer
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answers