mojomatt Posted March 28, 2011 Share Posted March 28, 2011 Hi, For some reason I'm unable to move to the first record in the recordset when using the following code. Basically I'm querying AD for a list of all computer objects, showing the count of objects (which moves your cursor to the last record), then I'm trying to move back to the first record so that my Do loop will start with the first record. My count of objects in the recordset is 58 but my do loop shows 1 record then exits. If I put the recordcount statement after the Do loop, all is well. Any thoughts? expandcollapse popupConst $adUseClient = 3 $strDomain="mydomain.com" $strDistinguishedDomain="dc=mydomain,dc=com" $strInstallerUserName="admin" $strInstallerUserPassword="mypassword" $strBase = "<LDAP://" & $strDomain & "/" & $strDistinguishedDomain & ">" ;~ ' Filter on computer objects. $strFilter = "(objectClass=computer)" ;~ ' Comma delimited list of attribute values to retrieve. $strAttributes = "DistinguishedName" ;~ ' Construct the LDAP syntax query. $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objadoConnection.Open ("Provider=ADsDSOObject;cursorLocation="& $adUseClient&";User ID=" & $strDomain & "\" & $strInstallerUserName& ";Password=" & $strInstallerUserPassword & ";Encrypt Password=True;") $objadoCommand.ActiveConnection = $objadoConnection $objadoCommand.CommandText = $strQuery $objadoCommand.Properties("Page Size") = 1000 $objadoCommand.Properties("Timeout") = 30 $objadoCommand.Properties("Cache Results") = False ;~ ' Run the query. $rsadoRecordset = $objadoCommand.Execute ;~ ' Display number of records. ;~ ' This positions the cursor at the end of the recordset. msgbox (0,"",$rsadoRecordset.RecordCount) ;~ ' Move the cursor back to the beginning. $rsadoRecordset.MoveFirst ; I couldn't get this working ;~ ' Enumerate the resulting recordset. Do ;~ ' Retrieve values and display. $strTemp = $rsadoRecordset.Fields("DistinguishedName").Value MsgBox(0,"",$strtemp) $rsadoRecordset.MoveNext Until $rsadoRecordset.EOF Link to comment Share on other sites More sharing options...
mojomatt Posted March 28, 2011 Author Share Posted March 28, 2011 I figured out my own problem I wasn't caching the results of the query so apparently you only get 1 shot to parse through the data. Once I set the cache results property to TRUE, all was well. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now