Networking Forums

Networking Forums > Computer Networking > Windows Networking > How to output the home directory of a list of domain users

Reply
Thread Tools Display Modes

How to output the home directory of a list of domain users

 
 
Spin
Guest
Posts: n/a

 
      03-14-2008, 02:40 PM
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


 
Reply With Quote
 
 
 
 
Paul Bergson [MVP-DS]
Guest
Posts: n/a

 
      03-14-2008, 02:54 PM
Here is an example of all users w/o a home directory using the freeware
utility adfind from joeware.net

adfind -f
"(&(objectCategory=person)(objectClass=user)(!(hom eDirectory=*)))" -b
"dc=yourdomain,dc=com" samaccountname homeDirectory -list

--
Paul Bergson
MVP - Directory Services
MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup
This posting is provided "AS IS" with no warranties, and confers no rights.

"Spin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
lforbes
Guest
Posts: n/a

 
      03-14-2008, 06:39 PM
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
>
>
>

 
Reply With Quote
 
SunTzu77
Guest
Posts: n/a

 
      03-14-2008, 09:24 PM
Hi Spin,

I found the following helpful when I wanted to do a similar exercise.

If you haven't sorted it by Monday when I am back in work I will copy the
modified version in this post for you that just brings back the samAccount
name and the Home Directory. into an excel spreadsheet.

http://www.wisesoft.co.uk/Scripts/di...pt.aspx?id=133



"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
>
>
>

 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      03-14-2008, 11:22 PM
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
>>
>>
>>



 
Reply With Quote
 
lforbes
Guest
Posts: n/a

 
      03-15-2008, 03:56 AM
Thanks. I posted and then tried to edit but MS boards don't let you do that.
I bind to the user object with this script simply because I use it 99% of the
time to pull the user info and then put info back into AD like if I want to
change 1000 emails or 1000 descriptions to individual ones from an excel
sheet. I just modified it for his purpose.

I have 2500 AD users and it runs pretty fast so I don't worry about slowing
it down any.

Cheers,
Lara

"Richard Mueller [MVP]" wrote:

> 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
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Spin
Guest
Posts: n/a

 
      03-16-2008, 05:39 AM
"Richard Mueller [MVP]" <rlmueller-(E-Mail Removed)> wrote in
message news:%(E-Mail Removed)...
> 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):

<snipped>

Hiya Rich:

I get the following error when running your script:

---------------------------
Windows Script Host
---------------------------
Script: C:\Documents and Settings\Admin\Desktop\Retrieve HomDrv of user.vbs
Line: 2
Char: 1
Error: Object required: 'objExcel'
Code: 800A01A8
Source: Microsoft VBScript runtime error

---------------------------
OK
---------------------------


 
Reply With Quote
 
lforbes
Guest
Posts: n/a

 
      03-16-2008, 05:01 PM
Spin,

Try my script. It should work as-is if you change your network in the script.
Just open a blank xls document. With vbscript you can just drop it on the
vbs file and it will open.

You don't have to worry about the lack of time taken to bind to users. I
have 2500 users and it takes no time.

You need to modify the following line to include homedirectory as well.

"SELECT ADsPath, givenName, SN, homedrive, homedirectory, 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.homedirectory

"Spin" wrote:

> "Richard Mueller [MVP]" <rlmueller-(E-Mail Removed)> wrote in
> message news:%(E-Mail Removed)...
> > 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):

> <snipped>
>
> Hiya Rich:
>
> I get the following error when running your script:
>
> ---------------------------
> Windows Script Host
> ---------------------------
> Script: C:\Documents and Settings\Admin\Desktop\Retrieve HomDrv of user.vbs
> Line: 2
> Char: 1
> Error: Object required: 'objExcel'
> Code: 800A01A8
> Source: Microsoft VBScript runtime error
>
> ---------------------------
> OK
> ---------------------------
>
>
>

 
Reply With Quote
 
Spin
Guest
Posts: n/a

 
      03-17-2008, 01:52 PM
"SunTzu77" <(E-Mail Removed)> wrote in message
news2FD0C4F-91BD-48B7-AFF5-(E-Mail Removed)...
> Hi Spin,
>
> I found the following helpful when I wanted to do a similar exercise.
>
> If you haven't sorted it by Monday when I am back in work I will copy the
> modified version in this post for you that just brings back the samAccount
> name and the Home Directory. into an excel spreadsheet.
>
> http://www.wisesoft.co.uk/Scripts/di...pt.aspx?id=133


I've not sorted it yet. If you're still willing, I'll take you up on your
offer.



 
Reply With Quote
 
Phillip Windell
Guest
Posts: n/a

 
      03-17-2008, 03:39 PM
Look for the old Tool from Somarsoft called DumpSec (formerly DumpACL).

SystemTools.com - Windows NT/2000/XP/2003 System Management Software
http://www.somarsoft.com/



--
Phillip Windell
www.wandtv.com

The views expressed, are my own and not those of my employer, or Microsoft,
or anyone else associated with me, including my cats.
-----------------------------------------------------

"Spin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "SunTzu77" <(E-Mail Removed)> wrote in message
> news2FD0C4F-91BD-48B7-AFF5-(E-Mail Removed)...
>> Hi Spin,
>>
>> I found the following helpful when I wanted to do a similar exercise.
>>
>> If you haven't sorted it by Monday when I am back in work I will copy the
>> modified version in this post for you that just brings back the
>> samAccount
>> name and the Home Directory. into an excel spreadsheet.
>>
>> http://www.wisesoft.co.uk/Scripts/di...pt.aspx?id=133

>
> I've not sorted it yet. If you're still willing, I'll take you up on your
> offer.
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wu-ftp directory list failure hendedav@yahoo.com Linux Networking 12 06-05-2006 10:36 PM
No Domain Users listed on user list Flavia Windows Networking 1 08-23-2004 03:11 PM
PROFTPD: Some users cannot upload files, some users cannot get directory listing Marc Linux Networking 0 10-24-2003 06:18 AM
PROFTPD: Some users cannot upload files, some users cannot get directory listing Marc Linux Networking 1 10-24-2003 05:50 AM
"List of users" not available with sharing in a NT domain Oliver Schulze L. Windows Networking 0 07-07-2003 07:20 PM



1 2 3 4 5 6 7 8 9 10 11