Jump to content
Sign in to follow this  

MoveFirst not working

Recommended Posts


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?

Const $adUseClient = 3


        $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.
        ;~     ' Retrieve values and display.
            $strTemp = $rsadoRecordset.Fields("DistinguishedName").Value
        Until $rsadoRecordset.EOF

Share this post

Link to post
Share on other sites

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.


Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...