You probably want objUser.homeDirectory as well as objUser.homeDrive. And,
if you retrieve the attribute values with ADO, there is no need to bind to
the user object (which slows down the script). A big advantage of ADO is
that it retrieves all attribute values in one operation, without the need to
bind to each AD object. I would suggest (in part):
==========
' Write column headings in first row of spreadsheet.
objExcel.Cells(1, 1).Value = "Logon Name"
objExcel.Cells(1, 2).Value = "Last Name"
objExcel.Cells(1, 3).Value = "First Name"
objExcel.Cells(1, 4).Value = "Home Drive"
objExcel.Cells(1, 5).Value = "Home Directory"
objCommand.CommandText = "SELECT sAMAccountName, sn, givenName, homeDrive,
homeDirectory " _
& "FROM 'LDAP://dc=domain,dc=local' " _
& "WHERE objectCategory='person' AND objectClass='user'"
Set objRecordSet = objCommand.Execute
' Start adding users in row 2.
i = 2
Do Until objRecordSet.EOF
objExcel.Cells(i, 1).Value = objRecordSet.Fields("sAMAccountName").Value
objExcel.Cells(i, 2).Value = objRecordSet.Fields("sn").Value
objExcel.Cells(i, 3).Value = objRecordSet.Fields("givenName").Value
objExcel.Cells(i, 4).Value = objRecordSet.Fields("homeDrive").Value
objExcel.Cells(i, 5).Value = objRecordSet.Fields("homeDirectory").Value
i = i + 1
objRecordset.MoveNext
Loop
' Clean up.
objRecordSet.Close
objConnection.Close
============
If desired, you could retrieve the DNS domain name ("dc=domain,dc=local" in
the example) programmatically from the RootDSE object. For example:
============
' Determine the DNS domain from the RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
objCommand.CommandText = "SELECT sAMAccountName, sn, givenName, homeDrive,
homeDirectory " _
& "FROM 'LDAP://" & strDNSDomain & "' " _
& "WHERE objectCategory='person' AND objectClass='user'"
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net
--
"lforbes" <(E-Mail Removed)> wrote in message
news:4887BFB6-90A2-4F74-AEEA-(E-Mail Removed)...
> 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, homedrive, samAccountName,
> telephoneNumber, mail, description, department FROM 'LDAP://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.homedrive
> i = i + 1
> objRecordset.MoveNext
> Loop
>
> objConnection.Close
>
>
> "Spin" wrote:
>
>> Gurus,
>>
>> Given a list of users in the domain (say, users.txt) is there a dsquery
>> command that will output their home directory into a nice to read format?
>>
>> --
>> Spin
>>
>>
>>