Asked by:
Where to add "Properties("Page Size") = 100" in the script?

Question
-
Hi Experts,
I am getting out of memory error when running this script for thousands of OUs. To overcome, I decided to add Page Size but not sure where should I put in the script.
Any idea?
Option Explicit Const ADS_SCOPE_SUBTREE = 2 Dim ObjConn, ObjRS, ObjRootDSE Dim StrSQL, StrDomName, ObjOU Set ObjRootDSE = GetObject("LDAP://RootDSE") StrDomName = Trim(ObjRootDSE.Get("DefaultNamingContext")) Set ObjRootDSE = Nothing StrSQL = "Select Name, ADsPath From 'LDAP://" & StrDomName & "' Where ObjectCategory = 'OrganizationalUnit' And Name <> 'Domain Controllers'" Set ObjConn = CreateObject("ADODB.Connection") ObjConn.Provider = "ADsDSOObject": ObjConn.Open "Active Directory Provider" Set ObjRS = CreateObject("ADODB.Recordset") ObjRS.Properties("Page Size") = 1000 ObjRS.Open StrSQL, ObjConn If Not ObjRS.EOF Then ObjRS.MoveLast: ObjRS.MoveFirst WScript.Echo vbNullString WScript.Echo "Total OU: " & Trim(ObjRS.RecordCount) & VbCrLf & "===================" WScript.Echo vbNullString While Not ObjRS.EOF Set ObjOU = GetObject(Trim(ObjRS.Fields("ADsPath").Value)) If StrComp(Right(Trim(ObjOU.Parent), Len(Trim(ObjOU.Parent)) - 7), StrDomName, VbTextCompare) = 0 Then WScript.Echo "Parent OU: " & Trim(ObjRS.Fields("Name").Value) GetChild(ObjOU) End If ObjRS.MoveNext Set ObjOU = Nothing Wend End If ObjRS.Close: Set ObjRS = Nothing ObjConn.Close: Set ObjConn = Nothing Private Sub GetChild(ThisObject) Dim ObjChild, StrThisParent For Each ObjChild In ThisObject If StrComp(Trim(ObjChild.Class), "OrganizationalUnit", VbTextCompare) = 0 Then WScript.Echo vbTab & ">> Child OU: " & Right(Trim(ObjChild.Name), Len(Trim(ObjChild.Name)) - 3) GetGrandChild (ObjChild.ADsPath) End If Next End Sub Private Sub GetGrandChild (ThisADsPath) Dim ObjGrand, ObjItem Set ObjGrand = GetObject(ThisADsPath) For Each ObjItem In ObjGrand If StrComp(Trim(ObjItem.Class), "OrganizationalUnit", VbTextCompare) = 0 Then WScript.Echo vbTab & vbTab & ">> Child OU: " & Right(Trim(ObjItem.Name), Len(Trim(ObjItem.Name)) - 3) End If GetGrandChild Trim(ObjItem.ADsPath) Next Set ObjGrand = Nothing End Sub
Monday, June 25, 2018 5:27 AM
All replies
-
What is wrong with where you have it now?
\_(ツ)_/
Monday, June 25, 2018 5:30 AM -
I am getting following error while running it for bulk OUs.
Provider: The size limit for this request was exceeded.
Monday, June 25, 2018 5:51 AM -
So change it to something less than 1000.
\_(ツ)_/
Monday, June 25, 2018 5:54 AM -
I did run the script without putting Page Size and getting this error.
Now, I want to use Page Size property to avoid this error but I am not sure where exactly should I put in the scriptMonday, June 25, 2018 5:56 AM -
To use Page Size we have tom use the command object.
Run this to test.
Set objRootDSE = GetObject("LDAP://RootDSE") strDomName = objRootDSE.Get("DefaultNamingContext") strSQL = "Select Name, ADsPath From 'LDAP://" & strDomName & "' Where ObjectCategory = 'OrganizationalUnit' And Name <> 'Domain Controllers'" Set objConn = CreateObject("ADODB.Connection") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConn objCommand.Properties("Page Size") = 500 objCommand.Properties("Timeout") = 30 objCommand.Properties("Cache Results") = False objCommand.Properties("Searchscope") = 2 ' ADsScopeSubtree objCommand.CommandText = strSQL Set objRS = objCommand.Execute() While Not objRS.EOF WScript.Echo objRS.Fields("ADsPath").Value objRS.MoveNext Wend
\_(ツ)_/
- Edited by jrv Monday, June 25, 2018 6:24 AM
Monday, June 25, 2018 6:24 AM