    Dim objExcel
    Dim objRecordSet
    Dim u
    Dim c
    Dim strName
    Dim strPath
    Dim root
    Dim ou
    Dim TextXL
    Dim CRLF
    dim oArgs
    Dim grp
    Dim ObjUser

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

set oArgs=wscript.arguments
If oArgs.Count = 0 Then
       TextXL = InputBox("This scripts reads an Excel spreadsheet and adds" & _
       "users from the Windows NT DS via ADSI." & CRLF & CRLF & _
       "Before starting, change the DS root in the EXCEL spreadsheet to match " & _
       "your DS." & CRLF & CRLF & _
       "Type in the path of a file containing users to add or delete" & CRLF & CRLF & _
       "Sample Add User file: ADDUSERS.XLS" & CRLF & _
       "Sample Delete User file: DELUSERS.XLS" & CRLF)
    'Else file containing users is the first argument
    Else
      TextXL = oArgs.item(0)
    End If

    If TextXL = "" Then
       WScript.Echo "No input file provided. Stopping the script now."
       WScript.Quit(1)
    End If

Set objExcel = CreateObject("Excel.Application")
objExcel.workbooks.open TextXL
objExcel.Visible = True

i = 1
'50
    objCommand.CommandText = _
        "SELECT ADsPath, givenName, SN, samAccountName, physicalDeliveryOfficeName, mail, description, department FROM 'LDAP://OU=MyOU,dc=domain,dc=local' WHERE objectCategory='user'"
    Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
	strPath = objRecordSet.Fields("ADsPath").Value
    	Set objUser = GetObject(strPath)
    	objExcel.Cells(i,1) = objUser.samAccountName
    	objExcel.Cells(i,2) = objUser.SN
    	objExcel.Cells(i,3) = objUser.givenName
    	objExcel.Cells(i,4) = objUser.description
    	objExcel.Cells(i,5) = objUser.department
    	objExcel.Cells(i,6) = objUser.mail
    	objExcel.Cells(i,7) = objUser.physicalDeliveryOfficeName
    i = i + 1
    objRecordset.MoveNext
Loop

objConnection.Close

